突出显示父级标记图标

发布于 2025-02-01 13:42:23 字数 135 浏览 4 评论 0原文

我有一个带有3个图标的底部导航栏。这些图标中的每个图标都映射到自己的屏幕,每个屏幕中的每一个都可以导航到只有通过它可用的n个屏幕。如何在导航栏上突出显示当前屏幕的父母?我正在使用JetPack导航组件和XML,似乎一切都在自动完成,因此我无法手动指示行为。

I have an app that has a bottom navigation bar with 3 icons. Each one of those icons maps to their own screens and each one of those screens can navigate to n amount of screens only available through it. How can I highlight the parent of the current screen on the navigation bar? I am using jetpack navigation components and xml and it seems like everything is being done automatically so I have no way of dictating behavior by hand.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老旧海报 2025-02-08 13:42:23

考虑使用navController.ondestinationChangedListener

:例如:

private fun NavDestination.matchDestination(@IdRes destId: Int): Boolean =
    hierarchy.any { it.id == destId }

private val onDestinationChangedListener = NavController.OnDestinationChangedListener { _, destination, _ ->
    viewBinding.bottomNavigationView.menu.forEach { item ->
        if (destination.matchDestination(item.itemId)) {
            item.isChecked = true
        }
    }
}

navController.addOnDestinationChangedListener(onDestinationChangedListener)

Consider using NavController.OnDestinationChangedListener

For example:

private fun NavDestination.matchDestination(@IdRes destId: Int): Boolean =
    hierarchy.any { it.id == destId }

private val onDestinationChangedListener = NavController.OnDestinationChangedListener { _, destination, _ ->
    viewBinding.bottomNavigationView.menu.forEach { item ->
        if (destination.matchDestination(item.itemId)) {
            item.isChecked = true
        }
    }
}

navController.addOnDestinationChangedListener(onDestinationChangedListener)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文