Last active
February 4, 2016 03:53
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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