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

后端 未结 6 769
时光取名叫无心
时光取名叫无心 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:24

    Starting with 1.0.0-alpha07 you can use AppBarConfiguration to configure that behaviour.

    AppBarConfiguration has a Builder constructor so you can create a new Builder with a specific set of top level destinations, referenced by their id (this id is the one you set on your navigation layout).

    Create new AppBarConfiguration:

    val appBarConfiguration = AppBarConfiguration
                .Builder(
                        R.id.navigationHomeFragment,
                        R.id.navigationListFragment,
                        R.id.navigationProfileFragment)
                .build()
    

    Then, instead of setupActionBarWithNavController(this, navController) you need to call setupActionBarWithNavController(this, navController, appBarConfiguration)

    This is the right way to handle top navigation behaviours.

提交回复
热议问题