How to set title color in ActionBarSherlock?
Asked Answered
Q

5

15

How to set title color in ActionBarSherlock?

Which theming attributes should I use?

Quickly answered 27/4, 2012 at 13:57 Comment(2)
Color of the text (title); or color of the bar?Urus
<item name="android:actionBarStyle">@style/CustomActionBarStyle</item> I am using min version 7, the above andriod: prefix is not supporting getting error required min sdk version 11.There is any other suggetion to set title bar background color or image.Suellensuelo
H
35

From the ActionBarSherlock website

Parent Themes

In order for the custom action bar implementation to function your application must use Theme.Sherlock, Theme.Sherlock.Light, or Theme.Sherlock.Light.DarkActionBar, or your custom theme must use one of the aforementioned as its parent.

Mirrored Attributes

Due to limitations in Android's theming system any theme customizations must be declared in two attributes. The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation...

In short, that means you need to leave out the android: prefix when you're styling the ActionBar.

Theming the title color

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YOURTHEME" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">@style/YOURTHEME.ActionBarStyle</item>
<item name="actionBarStyle">@style/YOURTHEME.ActionBarStyle</item>
</style>

<style name="YOURTHEME.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:titleTextStyle">@style/YOURTHEME.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">@style/YOURTHEME.ActionBar.TitleTextStyle</item>
</style>

<style name="YOURTHEME.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">@color/YOUR_COLOR</item>
<item name="textColor">@color/YOUR_COLOR</item>
</style>
</resources>

NOTE

I haven't tested this. Also, what have you tried? You should searching before posting on SO in the future.

Hejaz answered 27/4, 2012 at 20:22 Comment(4)
Yes, I know but I didn't find about the "titleTextStyle" attribute, thanks!Quickly
It is not necessary, you can delete itFestoon
There are 2 errors on android:actionBarStyle and android:titleTextStyle: "android:actionBarStyle requires API level 11 (current min is 10)". How to overcome this?Boschbok
If your minSdkVersion is less than 11, you will need two files: values/styles.xml and values-v11/styles.xml. The android:-prefixed items should go into values-v11/styles.xml.Spec
K
43

You can easily do this with

getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>App Name</font>"));
Khartoum answered 25/12, 2012 at 9:52 Comment(4)
Good answer. Works in all levels of api's without any problem.Vaal
After dealing with styles and NOT getting it working with that (after really sifting through SO!) - this method worked! Thank you!Libratory
simple and effective!Sunder
Looks simple and elegant answer. But doesn't work for me.. don't know why.Bulgarian
H
35

From the ActionBarSherlock website

Parent Themes

In order for the custom action bar implementation to function your application must use Theme.Sherlock, Theme.Sherlock.Light, or Theme.Sherlock.Light.DarkActionBar, or your custom theme must use one of the aforementioned as its parent.

Mirrored Attributes

Due to limitations in Android's theming system any theme customizations must be declared in two attributes. The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation...

In short, that means you need to leave out the android: prefix when you're styling the ActionBar.

Theming the title color

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YOURTHEME" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">@style/YOURTHEME.ActionBarStyle</item>
<item name="actionBarStyle">@style/YOURTHEME.ActionBarStyle</item>
</style>

<style name="YOURTHEME.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:titleTextStyle">@style/YOURTHEME.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">@style/YOURTHEME.ActionBar.TitleTextStyle</item>
</style>

<style name="YOURTHEME.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">@color/YOUR_COLOR</item>
<item name="textColor">@color/YOUR_COLOR</item>
</style>
</resources>

NOTE

I haven't tested this. Also, what have you tried? You should searching before posting on SO in the future.

Hejaz answered 27/4, 2012 at 20:22 Comment(4)
Yes, I know but I didn't find about the "titleTextStyle" attribute, thanks!Quickly
It is not necessary, you can delete itFestoon
There are 2 errors on android:actionBarStyle and android:titleTextStyle: "android:actionBarStyle requires API level 11 (current min is 10)". How to overcome this?Boschbok
If your minSdkVersion is less than 11, you will need two files: values/styles.xml and values-v11/styles.xml. The android:-prefixed items should go into values-v11/styles.xml.Spec
S
24

i have changed the title color of this way:

in the Styles.xml file, i have added these styles

<style name="Theme.Styled" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/CustomActionBarStyle</item>
    <item name="android:actionBarStyle">@style/CustomActionBarStyle</item>
</style>

<style name="CustomActionBarStyle" parent="@style/Widget.Sherlock.ActionBar">
    <item name="titleTextStyle">@style/CustomTitleColorBar</item>
    <item name="android:titleTextStyle">@style/CustomTitleColorBar</item>
</style>

<!-- Style for the color title bar -->
<style name="CustomTitleColorBar" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Title">
    <item name="android:textColor">@android:color/white</item>
</style>

the last thing that i did was set the theme in the activity:

public static int THEME = R.style.Theme_Styled;

this line goes before super.onCreate() method

setTheme(THEME);

this is it.

Sciurine answered 28/8, 2012 at 16:49 Comment(2)
Do you need the "@style/" in the parent styles or would it also work without?Travertine
How do I change the background with this solution?Balmoral
F
1

you can do it from 2 places either in style.xml or programatically
1.From style.xml

2.Or in code

int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");  
TextView yourTextView = (TextView)findViewById(titleId);
yourTextView.setTextColor(getResources().getColor(R.color.myColor));

Or using actionbar you can also achieve this

getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>App Name</font>"));
Finnie answered 12/3, 2014 at 11:38 Comment(0)
C
1

I think you are trying to change the text color that is on the Menu, not the color of text that is in the Title in ActionBarSherlock.

When you use getSupportActionBar().SetTitle("My Title") to style this text you should use the code @Archie.bpgc. His answer is correct, but I believe that you are in need of the following code:

<style name="MyTheme.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Menu">
    <item name="android:textColor">@color/white</item>
    <item name="android:textSize">24sp</item>
    <item name="android:gravity">center</item>
</style>

See that you simply exchange parent =" TextAppearance.Sherlock.Widget.ActionBar.Title"> with parent = "TextAppearance.Sherlock.Widget.ActionBar.Menu">

Crista answered 1/10, 2015 at 17:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.