如何在Android上动态更改NavigationUI组件中的默认选项卡
在我的应用程序中,我想显示底部选项卡,当单击这些选项卡时,会显示一个片段。 为此,我使用BottomNavigationView和NavigationUI组件来显示片段 我的XML代码: 但始终显示默认选项卡的项目0 我希望写入条件并选中一个值,然后使用该值设置此NavigationUi和BottomNavigationView的默认选项卡 我该怎么做?在图中,您可以定义startDestination。 比如:如何在Android上动态更改NavigationUI组件中的默认选项卡,android,kotlin,uinavigationcontroller,android-architecture-navigation,android-navigation-graph,Android,Kotlin,Uinavigationcontroller,Android Architecture Navigation,Android Navigation Graph,在我的应用程序中,我想显示底部选项卡,当单击这些选项卡时,会显示一个片段。 为此,我使用BottomNavigationView和NavigationUI组件来显示片段 我的XML代码: 但始终显示默认选项卡的项目0 我希望写入条件并选中一个值,然后使用该值设置此NavigationUi和BottomNavigationView的默认选项卡 我该怎么做?在图中,您可以定义startDestination。 比如: val navHostFragment = supportFragment
val navHostFragment = supportFragmentManager.findFragmentById(R.id.homePage_fragmentNavHost) as NavHostFragment
val graphInflater = navHostFragment.navController.navInflater
val navGraph = graphInflater.inflate(R.navigation.home_navigator)
navGraph.startDestination = R.id.nav_xxxxx
navController.graph = navGraph
findViewById<BottomNavigationView>(R.id.homePage_bottomNavBar)
.setupWithNavController(navController)
在图中,您可以定义startDestination。
比如:
val navHostFragment = supportFragmentManager.findFragmentById(R.id.homePage_fragmentNavHost) as NavHostFragment
val graphInflater = navHostFragment.navController.navInflater
val navGraph = graphInflater.inflate(R.navigation.home_navigator)
navGraph.startDestination = R.id.nav_xxxxx
navController.graph = navGraph
findViewById<BottomNavigationView>(R.id.homePage_bottomNavBar)
.setupWithNavController(navController)
val navHostFragment = supportFragmentManager.findFragmentById(R.id.homePage_fragmentNavHost) as NavHostFragment
val graphInflater = navHostFragment.navController.navInflater
val navGraph = graphInflater.inflate(R.navigation.home_navigator)
navGraph.startDestination = R.id.nav_xxxxx
navController.graph = navGraph
findViewById<BottomNavigationView>(R.id.homePage_bottomNavBar)
.setupWithNavController(navController)