Navigation Drawer doesn't show fragments

后端 未结 2 935
旧巷少年郎
旧巷少年郎 2021-01-26 15:37

I\'ve created a new Android Studio Project and my MainActivity is a Navigation Drawer Activity.

So, I can\'t show up fragments. I\'ve read many post on internet and here

2条回答
  •  天涯浪人
    2021-01-26 16:01

    Latest - If you use Navigation Architecture Component, then you don't have to manually connect your fragments to your drawer MenuItem. The system will automatically tie you MenuItem to specific fragment If the id of the MenuItem in your menu/xyz_menu.xml matches the id of the destination in navigation/xyz_nav.xml, the NavController can then navigate to that destination.

    Follow the correct steps mentioned in the official documentation : https://developer.android.com/guide/navigation/navigation-ui#Tie-navdrawer

    Note :

    1. They have a sample app linked to the same article which you can refer.

    2. To get this is effect, do not implement onNavigationItemSelected otherwise it will override the system let you handle the navigation.

提交回复
热议问题