How to disable drawer option in specific fragments of an activity

℡╲_俬逩灬. 提交于 2019-12-04 16:18:59
MichaelStoddart

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

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