问题描述
我使用 Jetpack Navigation 来处理底部导航控制器.效果很好;但是,我正在寻找一种改进用户体验的方法.
I'm using Jetpack Navigation to handle the bottom navigation controller. It works great; however, I am looking for a way to improve the UX.
是否可以禁用用户当前导航到的标签?
我可以垃圾邮件"底部导航中的当前选项卡,它会重新加载数据和不必要的用户界面.如果这种行为(重新点击当前选项卡)是有意的,有没有办法保留片段的状态,以便在导航离开时&到,它不会重新创建?
I'm able to "spam" the current tab in the bottom navigation, which reloads data & the UI unnecessarily. If this behavior (of re-tapping the current tab) is intended, is there a way to retain the state of the fragment, so that when navigated away & to, it doesn't recreate?
我如何处理底部导航:
navController = NavHostFragment.findNavController(navigation_host_fragment)
NavigationUI.setupWithNavController(bottom_navigation_view, navController)
推荐答案
根据 这个问题:
随意设置一个OnNavigationItemReselectedListener
,它优先于NavigationUI设置的OnNavigationItemSelectedListener:setOnNavigationItemReselectedListener
bottom_navigation_view.setOnNavigationItemReselectedListener {
// Do nothing
}
这篇关于禁用底部导航控制器中的当前选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!