Remove up button from action bar when navigating using BottomNavigationView with Android Navigation UI library

后端 未结 6 838
时光取名叫无心
时光取名叫无心 2021-02-01 04:29

I\'ve created a small app that has three fragments for top-level navigation through a BottomNavigationView. If you launch the app and click on a navigation button on the bottom

6条回答
  •  Happy的楠姐
    2021-02-01 05:30

    Use this instead of setupWithNavController:

    navController.addOnNavigatedListener(new NavController.OnNavigatedListener() {
         @Override
         public void onNavigated(@NonNull NavController controller, @NonNull NavDestination destination) {
             toolbar.setTitle(destination.getLabel());
         }
    });
    

    Or the equivalent in Kotlin.

    The only thing setupWithNavController does is add a listener to change the toolbar title, and creates the up button. If you don't want the up button, just add a listener which changes the toolbar title only.

提交回复
热议问题