Hide Toolbar back arrow with NavigationComponent and BottomNavigationView

北城余情 提交于 2020-01-06 06:46:45

问题


I'm in the process of implementing NavigationComponent coupled with a BottomNavigationView and I am noticing that the back arrow is shown in the toolbar for all fragment destinations except the one specified as the startDestination in my navigation graph.

All examples of this implementation that I've been able to find show similar behavior. Hiding the back arrow for each associated fragment of a BottomNavigationView seems like a more natural design in my opinion, (hitting a back arrow in the Toolbar to navigate from tab 2 to tab 1 feels odd to me and I've never seen this before).

See the image below for an example and what I'm looking to achieve. Any way to accomplish this?


回答1:


If you are using a AppBarConfiguration should look like this.

val appBarConfiguration = AppBarConfiguration(
            setOf(
                R.id.homeFragment,
                R.id.dashboardFragment,
                R.id.notificationsFragment
            )
        )

setupActionBarWithNavController(navController!!, appBarConfiguration!!)

Which means that all of your fragments are top level destinations.

Heads up , when you hit back , you will get out of the app. So if you need another case you should configure onBackPressed for each fragment




回答2:


use getActionBar().setDisplayHomeAsUpEnabled(false) to remove home/back button from toolbar



来源:https://stackoverflow.com/questions/56670215/hide-toolbar-back-arrow-with-navigationcomponent-and-bottomnavigationview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!