1

Hello I want to hide Floating action bar button and bottom app bar in certain fragments , have tried different ways but I cannot get it to work. Is it even possible to do that or do I have to stick with regular navigation bar

val bottomNavigationMenu = findViewById<BottomNavigationView>(R.id.bottomNavMenu)
        val bottomAppBar = findViewById<BottomAppBar>(R.id.bottomAppBar)
        bottomNavigationMenu.background = null
        val navHostFragment =
            supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
        val controller = navHostFragment.navController
        bottomNavigationMenu.setupWithNavController(navController = controller) // setting up navigation bar
        bottomAppBar.setupWithNavController(navController = controller)
        // HIDING NAVIGATION BAR IN CERTAIN FRAGMENTS
        controller.addOnDestinationChangedListener { _: NavController, navDestination: NavDestination, _: Bundle? ->

            when (navDestination.id) {
                R.id.loginFragment, R.id.registrationFragment, R.id.passwordResetFragment, R.id.messageFragment, R.id.passwordChangeFragment, R.id.createMessageFragment -> bottomNavigationMenu.visibility =
                    GONE
                R.id.loginFragment, R.id.registrationFragment, R.id.passwordResetFragment, R.id.messageFragment, R.id.passwordChangeFragment, R.id.createMessageFragment -> bottomAppBar.visibility = GONE
                else -> bottomNavigationMenu.visibility = VISIBLE

            }

        }

main activity xml here

  • Where is this code? In your Fragment or Activity hosting your Fragments? – Izak Apr 13 '22 at 17:11
  • As an aside you can make your code more concise: `R.id.loginFragment, R.id.registrationFragment, R.id.passwordResetFragment, R.id.messageFragment, R.id.passwordChangeFragment, R.id.createMessageFragment -> { bottomNavigationMenu.visibility = GONE; bottomAppBar.visibility = GONE}` – Izak Apr 13 '22 at 17:14
  • @Izak the code is in the activity hosting the fragments, i tried your comment but it didn't work –  ziad smiali Apr 13 '22 at 18:27
  • @ziadsmiali Check this out https://stackoverflow.com/a/70765377/11943929 – Jarnojr Apr 14 '22 at 06:17

1 Answers1

0

You can use bottomNavgationMenu.isVisible = false

Dkathayat1
  • 216
  • 1
  • 8