I want to add custom up navigation from fragment using Navigation component
In my build.gradle(app)
I use androidx.appcompat:appcompat:1.1.0-
This set up also works and you won't need to override onSupportNavigateUp
in your activity:
NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration)
toolbar.setNavigationOnClickListener {
if (navController.currentDestination?.id == R.id.destinationOfInterest) {
// Custom behavior here
} else {
NavigationUI.navigateUp(navController, configuration)
}
}
I prefer to set up the Toolbar
since it will handle automatically the up navigation and open/close a DrawerLayout
if you have one.