简体   繁体   中英

Android Studio open navigation Drawer using fragment and handle back button press

i have create a navigation drawer using fragments which is working fine. The problem is when i click on back button in any fragment it it navigates me to login activity. how to handle the back button press in fragments??

You have to override onBackPressed().

@Override
public void onBackPressed() {
    if (this.drawerLayout.isDrawerOpen(GravityCompat.START)) {
        this.drawerLayout.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

Visit below Stackoverflow link where i put solution stepwise to handle multiple fragment on backpress. StackOverFlow Answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM