如何在某些片段中隐藏bottomAppBar和fab



你好,我想在某些片段中隐藏浮动操作栏按钮和底部应用程序栏,我尝试了不同的方法,但无法使其工作。有可能做到这一点吗?或者我必须坚持使用常规的导航栏吗

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
}
}

主活动xml此处

您可以使用bottomNavgationMenu.isVisible=false

最新更新