我如何将 android jet pack 与 BottomnavigationView java 一起使用,即使在谷歌文档上也只有 Kotline 代码,我很困惑
navigationUI.setupWithNavController(bottomNavigationView,Navigation.findNavController(this,R.id.nav_host_fragment));
navigationUI.setupWithNavController(bottomNavigationView,Navigation.findNavController(this,R.id.nav_host_fragment));
单击菜单图标,使用导航图绘制的屏幕进行导航
最佳答案
你做得对。只是导航图 xml 文件中 fragment 的 id 和菜单项的 id 应该相同。因此导航 Controller 知道要加载哪个 fragment 。
val navController = findNavController(activity!!, R.id.bottomNavFragment)
val navHostFragment = childFragmentManager.findFragmentById(R.id.bottomNavFragment)!!
// set navigation graph
navController.setGraph(R.navigation.nav_graph_nav_bottom)
bottomNavigation.setupWithNavController(navController)
关于java - 如何在android java中使用jetpack导航和bottomNavigationView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54600494/