Changing navigation back button icon dynamically doesn't work

318 Views Asked by At

I need to set navigation back button dynamically when I do this ` viewBinding.toolbar.navigationIcon?.setColorFilter(Color.parseColor(theme.primaryTextColor), PorterDuff.Mode.MULTIPLY) it doesn't effect changing color or if I do

viewBinding.toolbar.setNavigationIcon(R.drawable.ic_back) in MainActivity where ic_back is white back button it doesn't work it shows back button or if I add this app:navigationIcon="@drawable/ic_back" in xml it doesn't work but when I set app:theme="@style/ToolbarColoredBackArrow"
<style name="ToolbarColoredBackArrow" parent="AppTheme"> <item name="android:textColorSecondary">#FFFFFF</item> </style>

it works why? I should do this without using theme

1

There are 1 best solutions below

0
Harsh Modani On

If the toolbar is your support action bar, then this definitely works :

toolbar.setNavigationIcon(R.drawable.ic_back);

Or whatever you want to set the icon to, just that it has to be a drawable file.