在底部导航控制器中禁用当前选项卡 [英] Disabling the current tab in a bottom navigation controller

查看:106
本文介绍了在底部导航控制器中禁用当前选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jetpack导航来处理底部的导航控制器.效果很好;但是,我正在寻找一种改善用户体验的方法.

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.

是否可以禁用用户当前导航到的选项卡?

我能够在底部导航中向垃圾邮件"当前标签,从而重新加载数据并删除UI不必要.如果要进行这种行为(重新点击当前选项卡),则有一种方法可以保留片段的状态,以便在浏览&到,它不会重新创建?

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:

Feel free to set a OnNavigationItemReselectedListener, which takes precedence over the OnNavigationItemSelectedListener set by NavigationUI: setOnNavigationItemReselectedListener

bottom_navigation_view.setOnNavigationItemReselectedListener {
  // Do nothing
}

这篇关于在底部导航控制器中禁用当前选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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