8

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.

rome 웃
  • 1,821
  • 3
  • 15
  • 33
  • visit http://stackoverflow.com/questions/27074106/android-drawerlayout-setdrawerlockmode-not-working – Rooban Jan 07 '16 at 10:57
  • I see this not fix my case, the same issue: http://stackoverflow.com/questions/18413116/why-i-cant-lock-drawerlayout-with-layout-gravity . But no one can fix it. – rome 웃 Jan 07 '16 at 11:02

1 Answers1

1

Add gravity value too when using setDrawerLockMode();

Do this :

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

This should work

Burhan Shakir
  • 237
  • 4
  • 11