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

后端 未结 6 781
时光取名叫无心
时光取名叫无心 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条回答
  •  心在旅途
    2021-02-01 05:07

    You could set the navigation icon to null, or change the icon only for some destinations eg:

    1) In Kotlin:

    navController.addOnDestinationChangedListener { _, destination, _ ->
                toolbar.title = destination.label
                toolbar.navigationIcon = null
    }
    

    2) In Java:

    hostFragment.getNavController().addOnDestinationChangedListener(new OnDestinationChangedListener() {
        public final void onDestinationChanged(@NotNull NavController controller, @NotNull NavDestination destination, @Nullable Bundle arguments) {
            toolbar.setTitle(destination.getLabel());
            toolbar.setNavigationIcon(null);
        }
    });
    

提交回复
热议问题