How to disable drawer option in specific fragments of an activity

独自空忆成欢 提交于 2019-12-21 21:34:38

问题


I have an activity with 5 fragments, I used drawer layout in my activity for a drawer, but I want to use(enable) the drawer in only fragment 2 and I want to disable the drawer option in remaining fragments.

Can any one help me how to do this?


回答1:


Put two methods in the your activity, one to disable the drawer and one to enable it again, like so:

public void lockDrawer() {
    drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}


public void unlockDrawer() {
    drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}

Then in your fragments onCreateView(...) method put:

fragmentInteractionListener.lockDrawer();

for the fragments where the drawer should stay shut and for the fragments where the drawer should stay open put:

fragmentInteractionListener.unlockDrawer();

P.S: for tutorials in how to correctly implement a fragment interaction listener see:

https://developer.android.com/training/basics/fragments/communicating.html



来源:https://stackoverflow.com/questions/39953366/how-to-disable-drawer-option-in-specific-fragments-of-an-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!