how to fire an event when someone clicks anywhere on the screen in an android app?

前端 未结 7 524
暗喜
暗喜 2020-12-29 03:06

how can I catch the event when click occurs somewhere on the app screen? It doesn\'t matter if there is a button or something else. I just need to apply an onClick()

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 04:07

    Give your main layout an id, then

    LinearLayout root = (LinearLayout) findViewById(R.id.main_layout);
    root.setOnClickListener(new OnClickListener() {
        public void onClick()
        {
    
        }
    });
    

提交回复
热议问题