Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was able to solve my problem by using <code>DrawerLayout.DrawerListener</code>. This worked in my situation because when the back button was being pressed the drawer was still closing even though the method <code>onBackPressed()</code> wasn't being called. </p> <p>@MH said, "The DrawerLayout (I assume that's what you're using) will consume the back button event if the drawer is opened."</p> <p>Although in the documentation I could not find an explicit mention of this; there was some mention of the back button <a href="http://developer.android.com/design/patterns/navigation-drawer.html" rel="nofollow" title="Navigation Drawer Design">here</a>. Unfortunately it was not of much help.</p> <p>What @MH said explains why <code>onBackPressed()</code> was not being called when the drawer was opened, and why it was being called while it was closed.</p> <pre><code>drawerLayoutRight.setDrawerListener(this); </code></pre> <p>Where <code>drawerLayoutRight</code> is a <code>DrawerLayout</code>. And my listener looks like this: </p> <pre><code>@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(); } } </code></pre> <p><code>onDrawerOpened()</code>, <code>onDrawerSlide()</code> and <code>onDrawerStateChanged()</code> are all empty. Only one of my drawers is using the listener so I don't have to check the view. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload