Navigation graph with multiple top level destinations

前端 未结 4 1045
醉话见心
醉话见心 2020-12-09 10:40

I am implementing an android app (in Kotlin, but that is not relevant to the Problem) in my free time and I try to use android jetpack and new libraries. I have a single Act

4条回答
  •  爱一瞬间的悲伤
    2020-12-09 10:45

    I made simple example for this issue. https://github.com/isaul32/android-sunflower

    Create set of top level destinations at first

    val topLevelDestinations = setOf(R.id.garden_fragment,
            R.id.plant_list_fragment)
    appBarConfiguration = AppBarConfiguration.Builder(topLevelDestinations)
            .setDrawerLayout(drawerLayout)
            .build()
    

    and then override onSupportNavigateUp function like this

    override fun onSupportNavigateUp(): Boolean {
        return NavigationUI.navigateUp(navController, appBarConfiguration)
    }
    

提交回复
热议问题