Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable drawer layout from one side?

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

like image 278
Pranav Mahajan Avatar asked Jan 20 '14 11:01

Pranav Mahajan


2 Answers

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);
            }
        }
    });
like image 176
Gopal Gopi Avatar answered Sep 27 '22 18:09

Gopal Gopi


Try this

setDrawerLockMode (int lockMode, View drawerView)

drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, yourDrawer)
like image 31
Timothy T. Avatar answered Sep 27 '22 18:09

Timothy T.