ActionBar text color
how can I change the text color of the ActionBar? I've inherited the Holo Light Theme, I'm able to change the background of the ActionBar but I don't find out what is the attribute to tweak to change the text color.
Ok, I'm able to change the text color with the attribute android:textColorPrimary but it also changes the text color of the dropdown menu displayed when an overflow happen on the ActionBar buttons. Any idea how to change the color of those dropdown menu / List ?
Ok, I've found a better way. I'm now able to only change the color of the title. You can also tweak the subtitle.
Here is my styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/red</item>
</style>
</resources>
I was having the same problem as you, it's a Holo.Light theme but I wanted to style the ActionBar color, so I needed to change the text color as well and also both Title and Menus. So at the end I went to git hub and looked at source code until I find the damn correct style:
<?xml version="1.0" encoding="utf-8"?>
<!-- For honeycomb and up -->
<resources>
<style name="myTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/myTheme.ActionBar</item>
<item name="android:actionMenuTextColor">@color/actionBarText</item>
</style>
<style name="myTheme.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@drawable/actionbarbground</item>
<item name="android:titleTextStyle">@style/myTheme.ActionBar.Text</item>
</style>
<style name="myTheme.ActionBar.Text" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/actionBarText</item>
</style>
</resources>
so now all you have to do is set whatever @color/actionBarText
and @drawable/actionbarbground
you want!
I found a way that works well with any flavor of ActionBar
(Sherlock, Compat, and Native):
Just use html to set the title, and specify the text color. For example, to set the ActionBar text color to red, simply do this:
getActionBar()/* or getSupportActionBar() */.setTitle(Html.fromHtml("<font color="red">" + getString(R.string.app_name) + "</font>"));
You can also use the red hex code #FF0000
instead of the word red
. If you are having trouble with this, see Android Html.fromHtml(String) doesn't work for <font color='#'>text</font>.
Additionally, if you want to use a color resource, this code can be used to get the correct HEX String, and removing the alpha if needed (the font tag does not support alpha):
int orange = getResources().getColor(R.color.orange);
String htmlColor = String.format(Locale.US, "#%06X", (0xFFFFFF & Color.argb(0, Color.red(orange), Color.green(orange), Color.blue(orange))));
链接地址: http://www.djcxy.com/p/89626.html
上一篇: ShareActionProvider从AppCompat v7下拉菜单颜色
下一篇: ActionBar文字颜色