Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android上动态更改NavigationUI组件中的默认选项卡_Android_Kotlin_Uinavigationcontroller_Android Architecture Navigation_Android Navigation Graph - Fatal编程技术网

如何在Android上动态更改NavigationUI组件中的默认选项卡

如何在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

在我的应用程序中,我想显示底部选项卡,当单击这些选项卡时,会显示一个片段。 为此,我使用BottomNavigationView和NavigationUI组件来显示片段

我的XML代码:

但始终显示默认选项卡的项目0

我希望写入条件并选中一个值,然后使用该值设置此NavigationUi和BottomNavigationView的默认选项卡

我该怎么做?

在图中,您可以定义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)
在图中,您可以定义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)