禁用所有 View 的触摸事件的最佳方法是什么?
最佳答案
这是一个禁用某个 View 组的所有 subview 的功能:
/**
* Enables/Disables all child views in a view group.
*
* @param viewGroup the view group
* @param enabled <code>true</code> to enable, <code>false</code> 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);
}
}
}
关于android - 禁用所有 View 的触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5418510/