获取片段的视图,并禁用整个视图,可以使用以下方法:
FragmentManager
获取片段的视图:FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_container);
View fragmentView = fragment.getView();
fragmentView.setEnabled(false);
private void setViewAndChildrenEnabled(View view, boolean enabled) {
view.setEnabled(enabled);
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i< viewGroup.getChildCount(); i++) {
setViewAndChildrenEnabled(viewGroup.getChildAt(i), enabled);
}
}
}
调用该方法:
setViewAndChildrenEnabled(fragmentView, false);
这样就可以获取片段的视图,并禁用整个视图。
领取专属 10元无门槛券
手把手带您无忧上云