Kotlin 在片段中隐藏 appbarlayout
Kotlin hide appbarlayout inside fragment
我附有 1 activity 和 4 个片段。我的 activity 中有一个 appbarlayout。我的目标是在某些片段中隐藏此应用程序栏布局。可能吗?代码应该怎么写?
Activity.kt
val navController = this.findNavController(R.id.newsNavHostFragment)
NavigationUI.setupActionBarWithNavController(this, navController)
bottomNavigationView.setupWithNavController(newsNavHostFragment.findNavController())
navController.addOnDestinationChangedListener { _, destination, _ ->
//if you want to handle multiple fragments use switch instead of if.
if(destination.id == R.id.full_screen_destination) {
//current Fragment is the fragment you want and do what ever you want with the appBar
} else {
//current Fragment is not the fragment you want
}
}
我附有 1 activity 和 4 个片段。我的 activity 中有一个 appbarlayout。我的目标是在某些片段中隐藏此应用程序栏布局。可能吗?代码应该怎么写?
Activity.kt
val navController = this.findNavController(R.id.newsNavHostFragment)
NavigationUI.setupActionBarWithNavController(this, navController)
bottomNavigationView.setupWithNavController(newsNavHostFragment.findNavController())
navController.addOnDestinationChangedListener { _, destination, _ ->
//if you want to handle multiple fragments use switch instead of if.
if(destination.id == R.id.full_screen_destination) {
//current Fragment is the fragment you want and do what ever you want with the appBar
} else {
//current Fragment is not the fragment you want
}
}