【问题标题】:Is there a way to define the starting tab in the navigation advanced sample?有没有办法在导航高级示例中定义开始选项卡?
【发布时间】:2020-02-04 11:13:28
【问题描述】:

我正在从事项目NavigationAdvancedSamplearchitecture-components-samples 存储库。此项目显示了一种解决方法,以支持 BottomNavigationView 的每个选项卡的多个返回堆栈。

在此配置中,您为每个选项卡定义一个导航图,并让类扩展 NavigationExtensions 为您处理不同的返回堆栈。一切正常,但我找不到选择BottomNavigationView 的开始选项卡的方法。我试图调整NavigationExtensions,但没有成功。

默认情况下,应用程序启动时选择的选项卡是底部导航视图的第一个。例如,如何更改此行为以显示第二个或第三个选项卡?

【问题讨论】:

    标签: 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 项目作为第一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      • 2016-11-05
      • 1970-01-01
      • 2016-08-07
      相关资源
      最近更新 更多