I have a main activity that is situated with two navigation drawers. The left one is always accessible, but the right one is used for displaying some necessary lists and perform
I was able to solve my problem by using DrawerLayout.DrawerListener
. This worked in my situation because when the back button was being pressed the drawer was still closing even though the method onBackPressed()
wasn't being called.
@MH said, "The DrawerLayout (I assume that's what you're using) will consume the back button event if the drawer is opened."
Although in the documentation I could not find an explicit mention of this; there was some mention of the back button here. Unfortunately it was not of much help.
What @MH said explains why onBackPressed()
was not being called when the drawer was opened, and why it was being called while it was closed.
drawerLayoutRight.setDrawerListener(this);
Where drawerLayoutRight
is a DrawerLayout
. And my listener looks like this:
@Override
public void onDrawerClosed(View arg0) {
if(drawerLayoutRight.getDrawerLockMode(drawerFrameRight)!= 1){
drawerLayoutRight.setDrawerLockMode(1, drawerFrameRight);
}
ExcerciseList fragment = (ExcerciseList) getFragmentManager().findFragmentById(R.id.right_drawer);
if (fragment != null) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.remove(fragment).commit();
}
}
onDrawerOpened()
, onDrawerSlide()
and onDrawerStateChanged()
are all empty. Only one of my drawers is using the listener so I don't have to check the view.