How to change toolbar icon color programmatically and theme way? Please suggest the best way to change the color
CodePudding user response:
Programmatically you can change color like below
Drawable drawable = toolbar.getNavigationIcon();
drawable.setColorFilter(ContextCompat.getColor(appCompatActivity, colorId), PorterDuff.Mode.SRC_ATOP);
Also, you can change this through the theme.
<style name="ToolbarColoreTheme" parent="AppTheme">
<item name="android:textColorSecondary">INSERT_COLOR_HERE</item>
</style>
apply the above theme in your toolbar like below
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@ id/toolbar"
***app:theme="@style/ToolbarColoreTheme"***
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>