So I have single activity app with single toolbar placed in layout of activity.
The next code only works just to change color of navigation icon button if there is no fragment was inflated yet
binding.toolbar.setNavigationIconTint(ContextCompat.getColor(this, R.color.white))
But as soon as navigation component opens any of the fragment with arrow back button (if it can go back to previous fragment) then color of arrow icon of back button is different (it's black)
Even the following code doesn't help to change color of arrow icon of back button:
override fun onDestinationChanged(
controller: NavController,
destination: NavDestination,
arguments: Bundle?
) {
binding.toolbar.setNavigationIconTint(ContextCompat.getColor(this, R.color.white))
}
It's still black arrow
Why I can't change it when using fragments with NavigationComponent
and why it sets to some back color (default one or what)?
The navigation icon is being set by NavigationComponent
. It can be arrow back or it can be menu (hamburger) icon if current fragment is one of fragments set for AppBarConfiguration(fragments)
When I set it like this in onDestinationChanged
then it will be changed, but here I manually set icon and color, and I have to add logic if I should set arrow or menu icon, so it complicates everything and it's boilerplate code, because NavigationCompopnent
can handle it itself:
binding.toolbar.setNavigationIcon(R.drawable.ic_arrow) // or menu (need to add logic which icon should be used)
binding.toolbar.setNavigationIconTint(ContextCompat.getColor(this, R.color.white))
All I want is just to change color of navigation icon but not icon itself.
My app just can have different toolbar style (transparent or solid) based on current fragment. That's why I want to change icon color dynamically