How to change Toolbar home icon color
Solution 1
I solved it by editing styles.xml:
<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">INSERT_COLOR_HERE</item>
</style>
...then referencing the style in the Toolbar definition in the activity:
<LinearLayout
android:id="@+id/main_parent_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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/ToolbarColoredBackArrow"
app:popupTheme="@style/AppTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
Solution 2
Here is what you are looking for. But this also changes the color of radioButton etc. So you might want to use a theme for it.
<item name="colorControlNormal">@color/colorControlNormal</item>
Solution 3
I solved it programmatically using this code:
final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(Color.parseColor("#FFFFFF"), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
Revision 1:
Starting from API 23 (Marshmallow) the drawable resource abc_ic_ab_back_mtrl_am_alpha
is changed to abc_ic_ab_back_material
.
Solution 4
This answer maybe too late, but here is how I do it. Styling the toolbar will do the trick. Create toolbar.xml with following code.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_alignParentTop="true"
android:layout_gravity="bottom"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
and in the styles.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>
Finally, include the toolbar inside layout
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
Solution 5
Change your Toolbar Theme to ThemeOverlay.AppCompat.Dark
<?xml version="1.0" encoding="utf-8"?>
<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/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="vertical"
app:theme="@style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
and set it in activty
mToolbar = (Toolbar) findViewById(R.id.navigation);
setSupportActionBar(mToolbar);
Related videos on Youtube
Joshua W
Updated on October 09, 2021Comments
-
Joshua W over 2 years
I am using a android.support.v7.widget.Toolbar and learned from this post how to change the color of the hamburger icon to white, but the up/back arrow remains a dark color when I call
setDisplayHomeAsUpEnabled(true);
How can I make the arrow white as well?
Here is what my toolbar looks like when I call setDisplayHomeAsUpEnabled():
...and here is the relevant portion of my styles.xml file:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar"> <item name="colorPrimary">@color/primary</item> <item name="colorPrimaryDark">#194C5F</item> <item name="colorAccent">@color/accent</item> <item name="drawerArrowStyle">@style/WhiteDrawerIconStyle</item> </style> <style name="WhiteDrawerIconStyle" parent="Widget.AppCompat.DrawerArrowToggle"> <item name="spinBars">true</item> <item name="color">@android:color/white</item> </style>
-
Surender Kumar about 9 yearsYou can use white arrow png icon and replace with black one.
-
Joshua W about 9 yearsI'm trying to avoid that and just indicate a color as a style... if that's the only way I know I can do it via actionBarDrawerToggle.setHomeAsUpIndicator(R.drawable.arrow);
-
Joshua W about 9 years...also the png /com.android.support/appcompat-v7/21.0.3/res/drawable-xxxhdpi/abc_ic_ab_back_mtrl_am_alpha.png appears white
-
user2056563 about 9 years@JoshuaWitter Thanks it solved my issue, can you also please help me to detect the click on back button ? here is my question stackoverflow.com/questions/29138629/…
-
osrl about 9 years@JoshuaWitter even if it is white, it gets tinted. Change the
colorControlNormal
value
-
-
mbelsky almost 9 yearsAlso you can set
colorControlNormal
insteadandroid:textColorSecondary
-
Ishan Fernando over 7 yearsset this one also.
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
-
Dr. aNdRO over 7 yearsbut that will change the entire widget's color right? @mbelsky
-
Francisco Romero over 7 years@mbelsky Note that it requires API level 21.
-
Mavamaarten over 7 yearsThis should be the accepted answer. This achieves what I was looking for: <style name="ActionBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> <item name="colorControlNormal">###COLOR###</item> </style> apply the theme directly to the Toolbar.
-
Mohamed Hatem Abdu about 7 years@Error404 : it's added in API level 1 as u see here
-
Deepak over 6 yearsHi All, I have tried your code but I am not getting required result. In my toolbar.axml file I am setup theme is android:theme=@style/ThemeOverlay.AppCompat.Dark.ActionBar and in my styles.axml file I have write your given code but navigation bar back button color in no change.
-
AndroidDevBro about 6 yearsDoes anyone know how to change the colour of the icon on a single fragment instead of doing so globally?
-
AndroidDevBro about 6 yearsWould this work in a
Fragment
? If so, where would I put this code into? TheOnCreateView
method, the root of the class, or...? -
PayToPwn about 6 years@AndroidDevBro Yes, just put it in the OnCreate function and remember to update the resource as Nouman Tahir wrote in the revision (using R.drawable.abc_ic_ab_back_material instead of R.drawable.abc_ic_ab_back_mtrl_am_alpha) and getting the SupportActionBar like this: ((AppCompatActivity)getActivity()).getSupportActionBar().setHomeAsUpIndicator(upArrow);
-
user25 about 6 years@FranciscoRomero
colorControlNormal
doesn't require API level 21 -
Henry over 5 yearsbut AppTheme isn't referenced anywhere. is this a typo?
-
C. Skjerdal about 5 yearsI was surprised of the other answers, I always use this method
-
ataravati almost 5 yearsThe parent attribute is very important.
-
Zaraki596 about 4 yearsThis is by far best answer and it solves my problem
-
Yeung about 3 yearsNo..it would affect the normal text too but not the arrow