Option 1) Quick and easy way (toolbar only)
Since appcompat-v7-r23 you can use the following attributes directly on your Toolbar or its style:
app:titleTextColor="@color/primary_text" app:subtitleTextColor="@color/secondary_text"
If your minimum SDK is 23 and you are using native Toolbar , just change the namespace prefix to android .
In Java, you can use the following methods:
toolbar.setTitleTextColor(Color.WHITE); toolbar.setSubtitleTextColor(Color.WHITE);
These methods accept an int color not a color resource identifier!
Option 2) Override toolbar style and attributes
Layout /xxx.xml
<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" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" android:theme="@style/ThemeOverlay.MyApp.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" style="@style/Widget.MyApp.Toolbar.Solid"/>
values /styles.xml
<style name="Widget.MyApp.Toolbar.Solid" parent="Widget.AppCompat.ActionBar"> <item name="android:background">@color/actionbar_color</item> <item name="android:elevation" tools:ignore="NewApi">4dp</item> <item name="titleTextAppearance">...</item> </style> <style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar"> <item name="android:textColorPrimary">@color/actionbar_title_text</item> </style>
Help! My icons also changed color!
@PeterKnut reported that this affects the color of the overflow button, navigation box button, and return button. It also changes the color of the text SearchView .
Regarding icon colors: colorControlNormal inherits from
android:textColorPrimary for dark themes (white on black)android:textColorSecondary for light themes (black on white)
If you apply this to the action bar theme, you can adjust the color of the icon.
<item name="colorControlNormal">#de000000</item>
An error occurred in appcompat-v7 with r23, which required you to also redefine the native instance as follows:
<item name="android:colorControlNormal" tools:ignore="NewApi">?colorControlNormal</item>
Help! My SearchView is a mess!
Note. This section may be outdated.
Since you are using a search widget that for some reason uses a different back arrow (not visually, technically) than the one included in appcompat-v7, you must install it manually in the application theme. Supported support libraries are correctly colored. Otherwise, it will always be white.
<item name="homeAsUpIndicator">@drawable/abc_ic_ab_back_mtrl_am_alpha</item>
As for the text of the search view ... there is no easy way. After digging through its source, I found a way to get to the text view. I have not tested this, so please let me know in the comments if this does not work.
SearchView sv = ...;
Bonus: Override ActionBar Style and Style Attributes
The appropriate style for the appcompat-v7 action bar will look like this by default:
<style name="Widget.MyApp.ActionBar.Solid" parent="Widget.AppCompat.ActionBar.Solid"> <item name="background">@color/actionbar_color</item> <item name="elevation">4dp</item> <item name="titleTextStyle">...</item> </style> <style name="Theme.MyApp" parent="Theme.AppCompat"> <item name="actionBarStyle">@style/Widget.MyApp.ActionBar.Solid</item> <item name="actionBarTheme">@style/ThemeOverlay.MyApp.ActionBar</item> <item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item> </style>