I have An activity with a navGraph and a bottom Navigation bar with 2 menu items. My problem is that My Bottom Navigation Bar appears everywhere, detailFragment, aboutFragment, signInFragment and so on.
val navController = this.findNavController(R.id.myNavHostFragment)
val appBarConfiguration = AppBarConfiguration.Builder(
R.id.contactsFragment,
R.id.profileFragment
).build()
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)
val navView: BottomNavigationView = findViewById(R.id.nav_view)
NavigationUI.setupWithNavController(navView, navController)
How do i Limit it to just show on the 2 fragments on my menu Item?
This is how I solved It
navController.addOnDestinationChangedListener{ _, nd: NavDestination, _->
if(nd.id == R.id.contactsFragment || nd.id == R.id.profileFragment){
navView.visibility = View.VISIBLE
}else{
navView.visibility = View.GONE
}
To do this, use SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION . You may also need to use SYSTEM_UI_FLAG_LAYOUT_STABLE to help your app maintain a stable layout.
Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.
Go to your Navbar settings and find the navigation item you want to hide for a particular page. Click to edit and assign it a classname. You could assign it something like "hide-navigation-item."
For your fragment where it should be visible
navView.visibility = View.VISIBLE
Where it shouldn't be visible
navView.visibility = View.GONE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With