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

前端 未结 7 562
暗喜
暗喜 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 03:52

    I believe the easiest way is to override onUserInteraction in your Activity

    Just be aware that it won't fire when users focus on/off EditTexts and Spinners (probably other Widgets too). But it will fire every time the user touches the screen or presses a Button.

    But this makes it unnecessary to build listeners into your layouts or write additional methods to handle those listeners, so I believe it's the most trouble-free way to get what you want.

提交回复
热议问题