How can I disable all views inside the layout?

后端 未结 23 1400
一个人的身影
一个人的身影 2020-11-28 08:46

For example I have:



        
23条回答
  •  盖世英雄少女心
    2020-11-28 09:29

    Let's change tütü's code

    private void disableEnableControls(boolean enable, ViewGroup vg){
    for (int i = 0; i < vg.getChildCount(); i++){
       View child = vg.getChildAt(i);
       if (child instanceof ViewGroup){ 
          disableEnableControls(enable, (ViewGroup)child);
       } else {
         child.setEnabled(enable);
       }
     }
    }
    

    I think, there is no point in just making viewgroup disable. If you want to do it, there is another way I have used for exactly the same purpose. Create view as a sibling of your groupview :

    
    

    and at run-time, make it visible. Note: your groupview's parent layout should be either relative or frame layout. Hope this will help.

提交回复
热议问题