Android - Change Actionbar Title Text Color
Solution 1
wandering around StackOverflow I found this answer which finally worked.
I report it here:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/ActionBar</item>
...
</style>
<style name="ActionBar" parent="@android:style/Widget.ActionBar">
<item name="android:titleTextStyle">@style/ActionBar.Title</item>
<item name="android:subtitleTextStyle">@style/ActionBar.Subtitle</item>
...
</style>
<style name="ActionBar.Title">
<item name="android:textColor">@color/my_color</item>
</style>
<style name="ActionBar.Subtitle">
<item name="android:textColor">@color/my_color</item>
</style>
Solution 2
Using SpannableString
we can set Text Color of Actionbar title
SpannableString s = new SpannableString(title);
s.setSpan(new ForegroundColorSpan(Color.GREEN), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
getSupportActionBar().setTitle(s);
Solution 3
<style name="AppTheme" parent="android:style/Theme.Holo.Light">
<style name="AppTheme.TextView" parent="android:Widget.TextView">
You missed a symbol "@" here?
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
also
<style name="AppTheme.TextView" parent="@android:Widget.TextView">
Solution 4
You could find how to customize ActionBar
here. I recommend to use ToolBar
and Theme.AppCompat
instead - example.
Solution 5
I am assuming you are using ToolBar
as ActionBar
. Of all the answers, I think this is the easiest one to implement. And works on all API versions.
So here it is:
Action bar title uses textColorPrimary
as its text color. So to change that in styles.xml create a new style with an item for textColorPrimary
and set whatever color you need.
<style name="appBarTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:textColorPrimary">@color/colorRed</item>
</style>
Now, add that style as your theme for toolbar in the XML.
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="enterAlways"
android:id="@+id/toolbar"
android:theme="@style/appBarTheme">
</android.support.v7.widget.Toolbar>
And now you got what you need.
jack_the_beast
Updated on July 22, 2022Comments
-
jack_the_beast almost 2 years
I'm developing an app and I want to
change the textcolor of the actionbar title
. now, I defined a theme in my manifest:<application android:theme="@style/AppTheme"> </application>
which is defined in styles.xml:
<style name="AppTheme" parent="android:style/Theme.Holo.Light"> <item name="android:textViewStyle">@style/AppTheme.TextView</item> <item name="android:actionBarStyle">@style/AppTheme.ActionBarStyle</item> </style> <style name="AppTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar"> <item name="android:titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item> </style> <style name="AppTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title"> <item name="android:textColor">@color/themeapp</item> </style> <style name="AppTheme.TextView" parent="@android:style/Widget.TextView"> <item name="android:textColor">#FFFFFF</item> </style>
this doesn't work but I don't get why. this should work according to this answer.neither the textview style is working.
what I am doing wrong?
UPDATE: changed to meet Grace Feng answer below
-
jack_the_beast over 8 yearsoh, this is embarassing. anyway, this is not working anyway, actionbar title remains white and textviews reamains black
-
jack_the_beast over 8 yearsI have a NavigationDrawer in the activity, so it extends AbstractNavDrawerActivity. unfortunately I didn't write this code so I don't really know why the guy who written this used it this way :S
-
sunday over 8 yearsI see AbstractNavDrawerActivity and this activity is extended from ActionBarActivity. And your theme is form Theme.Holo . So it will not work. If you do not want to change the activity , just change the theme like stackoverflow.com/questions/29957822/…. it will work
-
jack_the_beast over 8 yearsif I put this like you suggested android studio is not able to find it and returns an error, all the suggestion include
:style
-
jack_the_beast over 8 yearsI did. I understend I should not use it for the application tab but rather for sigle views. But then my questio remains, how do I change the text color?
-
James over 7 yearsI followed this example setting @color/my_color to #000000, and my text inside the action bar is still white.
-
Mohammed over 6 yearsBoth the actionBar background and text colors became white.
-
JorgeAmVF almost 5 years
android:textColorPrimary
is very precise. I had to look at a lot of answers till I reached this and it worked. Thanks!