0
votes

the issue i have is, that i want to dynamically add top level destinations to my app or at least show the drawer icon on those fragments

currently i have my top level destinations defined like this

val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
val navView: NavigationView = findViewById(R.id.nav_view)
val navController = findNavController(R.id.nav_host_fragment)

appBarConfiguration = AppBarConfiguration(setOf(R.id.nav_all_images, R.id.nav_favourites), drawerLayout)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)

i want to dynamically add destinations to categories. when i add them like this:

val s = navView.menu.addSubMenu("Test")
val m = s.add("Category 1")
m.setOnMenuItemClickListener {
    navController.navigate(AllImagesFragmentDirections.listToDetail())
    drawerLayout.closeDrawers()
    return@setOnMenuItemClickListener true
}

it opens it but, with a back button.

is it possible to show the drawer icon / drawer on those destinations ?

1

1 Answers

0
votes

Ok i figured out a solution which works for me. i've added a new Fragment, and added it to the Set in the AppBarConfiguration. In the click listener i navigate directly to the fragment navcontroller.navigate(R.id.fragmentname) since it is in the top level destinations it will show the drawer