Disabling the current tab in a bottom navigation controller

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-30 03:16:38

问题


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.

Is it possible to disable the tab that the user is currently navigated to?

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?

How I handle the bottom navigation:

navController = NavHostFragment.findNavController(navigation_host_fragment)
NavigationUI.setupWithNavController(bottom_navigation_view, navController)

回答1:


As per this issue:

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

bottom_navigation_view.setOnNavigationItemReselectedListener {
  // Do nothing
}


来源:https://stackoverflow.com/questions/56689704/disabling-the-current-tab-in-a-bottom-navigation-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!