【问题标题】:Jetpack Navigation: ActionBar back arrow only for specific fragmentsJetpack Navigation:ActionBar 后退箭头仅适用于特定片段
【发布时间】:2019-01-05 07:04:22
【问题描述】:

我有一个底部导航的应用程序,它是列表之间的主要导航(如项目、标签等),所有这些片段应该是等效的,顶级 Fragments。导航运行良好,已设置好。

    bottom_navigation.let { bottomNavigationView ->
        NavigationUI.setupWithNavController(bottomNavigationView, navController)
    } 

我想从不同的顶级片段导航到较低级别的片段,这些片段在操作栏中应该有后退箭头。我可以使用以下代码将导航与操作栏连接起来。

    NavigationUI.setupActionBarWithNavController(this, navController)

问题在于,在这种情况下,所有片段都有一个后退箭头,所有顶级片段也是如此(除了我在导航编辑器中标记为起始目的地的片段)。是否可以将更多片段标记为起始片段或在导航中标记一些片段以不获取此返回箭头?

【问题讨论】:

    标签: android android-fragments architecture navigation android-jetpack


    【解决方案1】:

    是的,您可以通过以下方式实现:

    
    val appBarConfiguration = AppBarConfiguration(setOf(R.id.top_level_fragment1, R.id.top_level_fragment2, R.id.top_level_fragment3))
    
    setupActionBarWithNavController(navController, appBarConfiguration)
    
    

    通过使用AppBarConfiguration 传递目标(片段)的 id 列表,您的导航控制器会将这些视为顶级(无后退箭头)。

    这是link to the relevant android developers documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 1970-01-01
      • 2015-04-06
      • 2021-03-21
      相关资源
      最近更新 更多