Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

android - Disabling the current tab in a bottom navigation controller

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...