Disable the touch events for all the views

前端 未结 13 1388
暗喜
暗喜 2020-11-28 06:53

What\'s the best way to disable the touch events for all the views?

13条回答
  •  情歌与酒
    2020-11-28 07:15

    Here is a function for disabling all child views of some view group:

     /**
       * Enables/Disables all child views in a view group.
       * 
       * @param viewGroup the view group
       * @param enabled true to enable, false to disable
       * the views.
       */
      public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
        int childCount = viewGroup.getChildCount();
        for (int i = 0; i < childCount; i++) {
          View view = viewGroup.getChildAt(i);
          view.setEnabled(enabled);
          if (view instanceof ViewGroup) {
            enableDisableViewGroup((ViewGroup) view, enabled);
          }
        }
      }
    

提交回复
热议问题