Skip to content

Instantly share code, notes, and snippets.

@sudansh
Last active February 26, 2019 15:24
Show Gist options
  • Save sudansh/b22f9f87f87b05ffcdfb33c3d0901345 to your computer and use it in GitHub Desktop.
Save sudansh/b22f9f87f87b05ffcdfb33c3d0901345 to your computer and use it in GitHub Desktop.
Nav Controller Queries
1. //automatically handles back button
toolbar.setupWithNavController(navController)
2. //to make root fragment (or make back button gone in a particular fragment).
//This removes the back button and also disabled toolbar back button navigation (keyboard back button works)
private val rootIds = setOf(R.id.fragment1, R.id.fragment2....)
private val appBarConfiguration by lazy {AppBarConfiguration(rootIds)}
toolbar.setupWithNavController(navController,appBarConfiguration)
3. //for back button to work along with (2).
setSupportActionBar(toolbar)
setupActionBarWithNavController(navController, appBarConfiguration)
4. //Show back button on first screen itself
private val rootIds = setOf(0) //set no rootids.
private val appBarConfiguration by lazy {AppBarConfiguration(rootIds)}
setSupportActionBar(toolbar)
setupActionBarWithNavController(navController, appBarConfiguration)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment