7
votes

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!!

2

2 Answers

17
votes

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);
            }
        }
    });
9
votes

Try this

setDrawerLockMode (int lockMode, View drawerView)

drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, yourDrawer)