我想在某些片段中隐藏 bottomNavigationView。
我试过下面的代码,但它有闪烁的效果。(bottomNavigationView 在 nextFragment 变得可见之前隐藏。
val navController = this.findNavController(R.id.nav_host_home)
navController.addOnDestinationChangedListener { _, destination, _ ->
when (destination.id) {
R.id.searchArticlesFragment -> bnvMain.visibility = View.GONE
R.id.articleFragment -> bnvMain.visibility = View.GONE
else -> bnvMain.visibility = View.VISIBLE
}
}
Run Code Online (Sandbox Code Playgroud)
我也试过另一个代码。但它会调整片段的大小。并在目标片段中给出 OutOfMemoryException。
supportFragmentManager.registerFragmentLifecycleCallbacks(object :
FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentViewCreated(
fm: FragmentManager,
f: Fragment,
v: View,
savedInstanceState: Bundle?
) {
when (f) {
is SearchArticlesFragment -> bnvMain.visibility = View.GONE
is ArticleDetailsFragment -> bnvMain.visibility = View.GONE
else -> bnvMain.visibility = View.VISIBLE
}
}
}, true)
Run Code Online (Sandbox Code Playgroud)
请帮助我如何以正确和最好的方式隐藏底部导航视图?这是我可以隐藏底部导航视图的唯一方法吗?youtube …
android android-fragments kotlin android-navigation android-bottomnav