Skip to content

Instantly share code, notes, and snippets.

@himattm
Last active February 4, 2016 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save himattm/5f4942bff96d26f42055 to your computer and use it in GitHub Desktop.
Save himattm/5f4942bff96d26f42055 to your computer and use it in GitHub Desktop.
Good onBackPressed() behavior closing the navigation drawer when it is open and going back when it is not.
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
// If the drawer is open close the drawer
drawer.closeDrawer(GravityCompat.START);
} else {
// Otherwise do the back pressed operation
super.onBackPressed();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment