How to set onClickListener to the WHOLE screen in Android?

后端 未结 2 1790
情书的邮戳
情书的邮戳 2021-01-19 04:06

The xml layout file looks like:



         


        
相关标签:
2条回答
  • 2021-01-19 04:21

    You can add a transparent view over your layout and set listener for this view. It will intercept all click events.

    0 讨论(0)
  • 2021-01-19 04:32

    You can do this:

    ViewTreeObserver viewTreeObserver = myView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {...}
    

    From the docs of ViewTreeObserver:

    A view tree observer is used to register listeners that can be notified of global changes in the view tree. Such global events include, but are not limited to, layout of the whole tree, beginning of the drawing pass, touch mode change

    0 讨论(0)
提交回复
热议问题