如何从另一个图形导航?喷气背包高级示例

时间:2021-02-09 07:50:38

标签: android-fragments android-jetpack-navigation

我正在寻找来自 google 的高级示例:https://github.com/android/architecture-components-samples/tree/main/NavigationAdvancedSample

他们像这样从 MainActivity 定义底部导航栏:

  private fun setupBottomNavigationBar() {
    val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_nav)

    val navGraphIds = listOf(R.navigation.home, R.navigation.list, R.navigation.form)

    // 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
    bottomNavigationView
}

有 3 个不同的导航图,如何在片段中单击按钮时从一个图导航到另一个保持状态?

0 个答案:

没有答案