【发布时间】:2019-06-05 13:08:04
【问题描述】:
我有一个带有 navGraph 的活动和一个带有 2 个菜单项的底部导航栏。 我的问题是My Bottom Navigation Bar到处出现,detailFragment、aboutFragment、signInFragment等等。
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)
我如何限制它只显示在我的菜单项上的 2 个片段上?
我就是这样解决的
navController.addOnDestinationChangedListener{ _, nd: NavDestination, _->
if(nd.id == R.id.contactsFragment || nd.id == R.id.profileFragment){
navView.visibility = View.VISIBLE
}else{
navView.visibility = View.GONE
}
【问题讨论】:
-
感谢您在解决方案中进行编辑,为我节省了一些时间!
-
不客气@SlowDeep,快乐编码
标签: kotlin android-jetpack android-bottomappbar android-jetpack-navigation