I'm using the new v7 Toolbar and for the life of me can't figure out how to change the color of the title. I've set the @style of the Toolbar to a style declared in styles.xml and applied a titleTextStyle with a textColor. Am I missing something? I'm coding for Lollipop but testing currently on a Kitkat device.
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<style name="ActionBar" parent="Theme.AppCompat">
<item name="android:background">@color/actionbar_background</item>
<item name="android:titleTextStyle">@style/ActionBar.TitleTextStyle</item>
</style>
<style name="ActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionbar_title_text</item>
</style>
</resources>
actionbar.xml:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
style="@style/ActionBar"/>
Best Answer
Option 1) The quick and easy way (Toolbar only)
Since appcompat-v7-r23 you can use the following attributes directly on your
Toolbar
or its style:If your minimum SDK is 23 and you use native
Toolbar
just change the namespace prefix toandroid
.In Java you can use the following methods:
These methods take a color int not a color resource ID!
Option 2) Override Toolbar style and theme attributes
layout/xxx.xml
values/styles.xml
Help! My icons changed color too!
@PeterKnut reported this affects the color of overflow button, navigation drawer button and back button. It also changes text color of
SearchView
.Concerning the icon colors: The
colorControlNormal
inherits fromandroid:textColorPrimary
for dark themes (white on black)android:textColorSecondary
for light themes (black on white)If you apply this to the action bar's theme, you can customize the icon color.
There was a bug in appcompat-v7 up to r23 which required you to also override the native counterpart like so:
Help! My SearchView is a mess!
Note: This section is possibly obsolete.
Since you use the search widget which for some reason uses different back arrow (not visually, technically) than the one included with appcompat-v7, you have to set it manually in the app's theme. Support library's drawables get tinted correctly. Otherwise it would be always white.
As for the search view text...there's no easy way. After digging through its source I found a way to get to the text view. I haven't tested this so please let me know in the comments if this didn't work.
Bonus: Override ActionBar style and theme attributes
Appropriate styling for a default action appcompat-v7 action bar would look like this: