How to remove up navigation from a specific fragment while using Android Navigation Component Library.
1 min readAug 17, 2020
Before:
/**
* Connect the navigation controller to the NavHostFragment
*/
val navHostFragment = supportFragmentManager
.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
NavigationUI.setupActionBarWithNavController(this, navController)
To remove the up navigation button, create an AppBarConfiguration of all the fragments you don't want to contain the up button for navigation.
/**
* Connect the navigation controller to the NavHostFragment
*/
val appBarConfiguration = AppBarConfiguration
.Builder(
R.id.BooksFragment,
R.id.logInFragment
)
.build()
val navHostFragment = supportFragmentManager
.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)
I have now removed the up action button from both the BooksFragment and the LogInFragment.
Happy coding!