Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setDrawerLockMode not working in android?

I want to lock swipe left-right and right-left of DrawerLayout.

DrawerLayout drawerLayout;

onCreate:

drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

Click button to open drawerLayout:

drawerLayout.openDrawer(Gravity.LEFT);

and close:

drawerLayout.closeDrawers();

I try setDrawerLockMode in onCreate, onResume, onStart but not working, it still can open, close by swipe it.

Edit 2:

It work with:

android:layout_gravity="start"

and not work with:

android:layout_gravity="start|bottom"

Any helps. Thanks.

like image 300
rome 웃 Avatar asked Jan 07 '16 10:01

rome 웃


1 Answers

Add gravity value too when using setDrawerLockMode();

Do this :

drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);

This should work

like image 94
Burhan Shakir Avatar answered Nov 08 '22 12:11

Burhan Shakir