Change Navigation Icon
Change Toolbar navigation icon
toolbar.setNavigationIcon(R.drawable.ic_close_black_24dp)Change Icon color
val passiveColor = ContextCompat.getColor(context, R.color.selection_icon_passive)// val closeIcon = ContextCompat.getDrawable(context, R.drawable.ic_close_black_24dp)val closeIcon = ContextCompat.getDrawable(context, R.drawable.selector_ic_close)DrawableCompat.setTint(closeIcon!!, passiveColor)toolbar.navigationIcon = closeIconres/drawable/selector_ic_close
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_close_black_24dp" android:state_pressed="true" />
<item android:drawable="@drawable/ic_close_black_24dp" />
</selector>Restore Original Navigation Icon
Assuming you changed the navigation icon as per the above instruction, how do you restore the original back icon?
Option 1: R.attr.homeAsUpIndicator
toolbar.navigationIcon = context.getDrawableFromAttribute(R.attr.homeAsUpIndicator)NOTE: Refer Context.getDrawableFromAttribute
Option 2: R.drawable.abc_ic_ab_back_material
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material)NOTE: R.drawable.abc_ic_ab_back_material - resource is marked as private
Option 3: Save original drawable before switching
val originalNavigationIcon = toolbar.navigationIconNOTE: Becareful of UI state as sometimes toolbar.navigationIcon will be null
Option 4: Material Icon
Import back icon: Android Studio -> File -> New -> Vector Asset -> Clip Art -> arrow back
Use the method in Change Navigation Icon section.