14

How to set title color in ActionBarSherlock?

Which theming attributes should I use?

Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
Sander Versluys
  • 72,737
  • 23
  • 84
  • 91
  • Color of the text (title); or color of the bar? – Davek804 Apr 27 '12 at 20:09
  • 2
    @style/CustomActionBarStyle 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. – ramesh Mar 30 '13 at 06:52

5 Answers5

43

You can easily do this with

getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>App Name</font>"));
Ajmal Salim
  • 4,142
  • 2
  • 33
  • 41
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.

Community
  • 1
  • 1
adneal
  • 30,484
  • 10
  • 122
  • 151
  • Yes, I know but I didn't find about the "titleTextStyle" attribute, thanks! – Sander Versluys Apr 30 '12 at 08:06
  • 4
    It is not necessary, you can delete it – icastell Nov 30 '12 at 22:25
  • 2
    There are 2 errors on android:actionBarStyle and android:titleTextStyle: "android:actionBarStyle requires API level 11 (current min is 10)". How to overcome this? – kolobok Apr 12 '13 at 20:07
  • 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. – Michael Chang Sep 06 '13 at 19:18
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.

shontauro
  • 1,812
  • 1
  • 25
  • 26
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>"));
TanvirChowdhury
  • 2,498
  • 23
  • 28
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">

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102