Reputation: 2720
when i set lock and disable swipe on open and close drawer layout i cant close that by pressing on back button on the phone, when mode is not lock pressing back button cause of close that but when i change mode to for example :
drawer_layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
pressing back button couldn't close that
Upvotes: 2
Views: 1200
Reputation: 107
I think this is because you set the state to LOCKED_CLOSED so you cannot move from this state until you set it to the _UNLOCKED state. Check my answer here: https://stackoverflow.com/a/50304856/2873702
Basically you have to recall the function
drawer_layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
with the UNLOCKED parameter instead. I suggest to try using it in the onBackPressed function. You should do something like
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer_layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
drawer.closeDrawer(GravityCompat.START);
drawer_layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}else{
super.onBackPressed();
}
}
Upvotes: 0
Reputation: 4649
You need to close it programmatically because drawer is in lock mode and this will not be automatically close. Implement this method in your activity so that you can close it with programmatically.
See the documentation of DrawerLayout.LOCK_MODE_LOCKED_CLOSED
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
}else{
super.onBackPressed();
}
}
Upvotes: 1