记录一次使用 BottomNavigationView的坑
只要在最后一段设置了setupWithNavController BottomNavigationView死活点不了
private fun initNavView() {
val fragmentContainerView =
supportFragmentManager.findFragmentById(R.id.fragmentContainerView) as NavHostFragment
val navController = fragmentContainerView.navController
val appBarConfiguration = AppBarConfiguration(
setOf(
R.layout.fragment_video,
R.layout.fragment_image,
R.layout.fragment_appraise,
R.layout.fragment_introduction
)
)
setupActionBarWithNavController(navController, appBarConfiguration)
val navigationButton = findViewById<BottomNavigationView>(R.id.navigationButton)
navigationButton.setupWithNavController(navController)
}
处理办法
BottomNavigationView -> menu 的 item id
FragmentContainerView -> navGraph 的 fragment id
item id 和 fragment id 一定要对应起来!!!!!