简体   繁体   中英

How to disable navigation drawer of activity from within a fragment

I've been looking for an answer to this for a while but I haven't found any answers on the subject.

So I have my Main Activity which containers a toolbar, a nav drawer, and a frame layout (the container for my fragments). So on the start of the activity it starts a fragment to display and I can switch between different fragments and they all have the toolbar and nav drawer because their container is still main activity.

Except there is one problem. I want to make a new fragment and I don't want it to use a nav drawer or a toolbar. I figured out how to disable and hide the toolbar from within that specific fragment but I haven't been able to find out how to disable the nav drawer. The user can still swipe from left to right to open the nav drawer. I don't want them to be able to do that.

Also if I was going to disable it, I need to disable it from the fragment not the main activity because the navigation to this fragment is from a button that's inside another fragment

You can use :

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

This will lock drawer opening on swipe

Source : How to Disable drawer in fragment and back back to correct fragment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM