使用NavigationComponent和BottomNavigationView隐藏工具栏后退箭头 [英] Hide Toolbar back arrow with NavigationComponent and BottomNavigationView

本文介绍了使用NavigationComponent和BottomNavigationView隐藏工具栏后退箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与BottomNavigationView一起实现NavigationComponent的实现,我注意到所有片段目标的工具栏中都显示了向后箭头,但指定为 startDestination 在我的导航图中。

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.

我能够找到的所有实施示例都显示出类似的行为。在我看来,为BottomNavigationView的每个相关片段隐藏后退箭头似乎是一种更自然的设计,(在工具栏中单击后退箭头以从选项卡2导航至选项卡1对我来说很奇怪,我之前从未见过) 。

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?

推荐答案

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

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.

抬起头,当您回击时,您将退出应用程序(或者,如果配置为第一个片段,则在 BottomSheet s这样的行为)。因此,如果您需要其他情况,则应为每个片段配置 onBackPressed

Heads up , when you hit back , you will get out of the app (or if configured to the first fragment, in BottomSheets you get this behaviour for example). So if you need another case you should configure onBackPressed for each fragment

这篇关于使用NavigationComponent和BottomNavigationView隐藏工具栏后退箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆