【问题标题】:Is there a way to define the starting tab in the navigation advanced sample?有没有办法在导航高级示例中定义开始选项卡?
【发布时间】:2020-02-04 11:13:28
【问题描述】:
【问题讨论】:
标签:
android
kotlin
android-architecture-navigation
android-components
【解决方案1】:
在 navGraphIds 中更改项目的顺序并在 bottomNavigationView 中选择项目对我有帮助。
private fun setupBottomNavigationBar() {
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_nav)
val navGraphIds = listOf(R.navigation.list, R.navigation.home, R.navigation.form)
bottomNavigationView.selectedItemId = R.id.list
// Setup the bottom navigation view with a list of navigation graphs
val controller = bottomNavigationView.setupWithNavController(
navGraphIds = navGraphIds,
fragmentManager = supportFragmentManager,
containerId = R.id.nav_host_container,
intent = intent
)
// Whenever the selected controller changes, setup the action bar.
controller.observe(this, Observer { navController ->
setupActionBarWithNavController(navController)
})
currentNavController = controller
}
因此,我将 R.id.list 项目作为第一个。