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 ?
Go to the app > res > values > themes > themes.
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 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))));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With