How to disable all click events of a layout?

后端 未结 7 1762
不知归路
不知归路 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:31

    You can pass View for disable all child click event.

    public static void enableDisableView(View view, boolean enabled) {
            view.setEnabled(enabled);
            if ( view instanceof ViewGroup ) {
                ViewGroup group = (ViewGroup)view;
    
                for ( int idx = 0 ; idx < group.getChildCount() ; idx++ ) {
                    enableDisableView(group.getChildAt(idx), enabled);
                }
            }
        }
    

提交回复
热议问题