I'm trying to get a callback, using the Jetpack Navigation library, when a new navigation event is completed in order to change the status bar color.
So far I've found
navController.addOnDestinationChangedListener
which notifies me when a new navigation starts but not when it completes, meaning that the enter/exit transitions have completed.
Is there any method to know when all navigation transitions have completed?
Navigation and motion Navigation transitions use motion to guide users between two screens in your app. They help users orient themselves by expressing your app's hierarchy, using movement to indicate how elements are related to one another.
Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.
You can use something like this:
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment)
navHostFragment?.childFragmentManager?.addOnBackStackChangedListener {
val currentFragment = navHostFragment.childFragmentManager.fragments.firstOrNull()
if (currentFragment is YourFragment) {
// your code here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With