Toolbar back button replaced for default icon for a half second when clicking on it

506 views Asked by At

i'm trying to replace default back button icon on toolbar like this:

toolbar.navigationIcon = R.drawable.lalala

it's fine, and it's working. But, when i'm trying to click back button, for a half second i can see default icon instead of mine. What i can do wrong ?

I'm using fragments and JetPack navigation.

1

There are 1 answers

7
Gabriele Mariotti On BEST ANSWER

Since you are using the Navigation Components, the expected behavior is the Up button displayed when you are on a non-root destination.
You can change it using the addOnDestinationChangedListener after your setup method.

Something like:

navController.addOnDestinationChangedListener { _, destination, _ ->
   if(destination.id == R.id.xxxx) {
       toolbar.setNavigationIcon(R.drawable.xxxx)
   } else {
       //
   }
}