7

I have made a double drawer layout without an actionbar something like this:

Using Navigation Drawer without TitleBar or ActionBar

My requirement is to disable the drawer on right when drawer on left is open & vice versa. So I'm hiding the right drawer button when left drawer is open & vice versa and that works fine.

But the problem is, even when I hide a button(left or right), the drawer still opens with horizontal swipe(right to left swipe). So how do I prevent the drawer from opening from swipe??

And since I'm doing it without ActionBarDrawerToggle inbuilt functions like

setOnDrawerOpenListener
setOnDrawerCloseListener

are not available.

Please Help!!

Community
  • 1
  • 1
Pranav Mahajan
  • 2,048
  • 2
  • 23
  • 36

2 Answers2

17

this may help you...

    drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {

        @Override
        public void onDrawerStateChanged(int arg0) {

        }

        @Override
        public void onDrawerSlide(View view, float arg1) {

        }

        @Override
        public void onDrawerOpened(View view) {
            if(view == rightDrawerView) {
                drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, leftDrawerView);
            } else if(view == leftDrawerView) {
                drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, rightDrawerView);
            }
        }

        @Override
        public void onDrawerClosed(View view) {
            if(view == rightDrawerView) {
                 drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, leftDrawerView);
            } else if(view == leftDrawerView) {
                 drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, rightDrawerView);
            }
        }
    });
Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43
  • 1
    This answer is almost perfect. But, when I close my left drawer, the right drawer "open-with-swipe" functionality must get enabled again. For that: 1. Write the exact onDrawerOpened(View view) code in onDrawerClosed(View view) 2. Change the mode to DrawerLayout.LOCK_MODE_UNLOCKED – Pranav Mahajan Jan 21 '14 at 05:32
  • @GopalRao where are you bro?? – Piyush May 08 '14 at 09:52
  • how to hide the drawer layout and with it the navigation view? – Kaveesh Kanwal Jun 16 '16 at 10:13
9

Try this

setDrawerLockMode (int lockMode, View drawerView)

drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, yourDrawer)
Timothy T.
  • 602
  • 4
  • 10