How to set onClickListener to the WHOLE screen in Android?

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

The xml layout file looks like:



         


        
2条回答
  •  忘掉有多难
    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

提交回复
热议问题