How to disable all click events of a layout?

后端 未结 7 1757
不知归路
不知归路 2020-12-16 10:51

I have a layout that contains many views. Is there an easy way to disable all its views click events?

7条回答
  •  时光取名叫无心
    2020-12-16 11:30

    Rather than iterating through all the children view, you can add this function to the parent Layout view

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }
    

    This will be called before the onTouchEvent for any child views, and if it returns true, the onTouchEvent for child views wont be called at all. You can create a boolean field member to toggle this state on and off if you want.

提交回复
热议问题