使用 NavigationComponent 和 BottomNavigationView 隐藏工具栏后退箭头

2024-01-09

我正在实现与 BottomNavigationView 结合使用的 NavigationComponent,并且我注意到工具栏中显示了所有片段目标的后退箭头,除了指定为startDestination在我的导航图中。

我找到的所有此实现的示例都显示了类似的行为。在我看来,隐藏 BottomNavigationView 的每个关联片段的后退箭头似乎是一种更自然的设计(点击工具栏中的后退箭头从选项卡 2 导航到选项卡 1 对我来说感觉很奇怪,我以前从未见过这种情况) 。

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


如果您使用的是AppBarConfiguration应该看起来像这样。

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

setupActionBarWithNavController(navController!!, appBarConfiguration!!)

这意味着您的所有片段都是顶级目的地。

注意,当您回击时,您将退出应用程序(或者如果配置为第一个片段,则在BottomSheet例如,您会得到这种行为)。因此,如果您需要另一种情况,您应该配置onBackPressed对于每个片段

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 NavigationComponent 和 BottomNavigationView 隐藏工具栏后退箭头 的相关文章

随机推荐