Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide the bottom navigation bar in certain fragments?

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
        }
like image 346
Doilio Matsinhe Avatar asked Jun 05 '19 13:06

Doilio Matsinhe


People also ask

How do I hide the bottom navigation bar in a fragment?

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.

How do I hide the bottom menu bar?

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.

How do I hide items in navigation?

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."


1 Answers

For your fragment where it should be visible

navView.visibility = View.VISIBLE

Where it shouldn't be visible

navView.visibility = View.GONE
like image 171
Artem Botnev Avatar answered Sep 27 '22 21:09

Artem Botnev