I am having a hard time with v7 Toolbar. What was once a simple task for ActionBar
, now seems overly complex. No matter what style I set, I cannot change either
if you want to change your icons to a Vector , create a new one.
and then in your Activity.java
:
Toolbar toolbar = findViewById(R.id.your_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationIcon(R.drawable.your_icon);
mToolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.your_icon2));
To change Vector icon Color, go to your Vector XML file.. in this case it will be your_icon.xml
, it will look like this :
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/Your_Color"
android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"/>
Note that we used these attributes to set the Vector's color :
android:fillColor="@color/Your_Color"
Edit : You can't use a color from your colors.XML or somewhere else , the color must be decalred directly in the Vector's XML file.. so it will look like this :
android:fillColor="#FFF"
add your default theme this line;
<item name="colorControlNormal">@color/my_color</item>
All the above solutions worked for me in API 21 or greater, but did not in API 19 (KitKat). Making a small change did the trick for me in the earlier versions. Notice Widget.Holo
instead of Widget.AppCompat
<style name="OverFlowStyle" parent="@android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">@drawable/ic_overflow</item>
</style>
In order to show the icon, use getSupportActionBar().setIcon(R.xxx.xxx)
In my case the code is:-
getSupportActionBar().setIcon (R.mipmap.ic_launcher);
There is a simple, easy and better approach, if we need to change only the color of hamburger/back icon.
It is better as it changes color only of desired icon, whereas colorControlNormal
and android:textColorSecondary
might affect other childviews of toolbar as well.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>