Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set title color in ActionBarSherlock?

How to set title color in ActionBarSherlock?

Which theming attributes should I use?

like image 390
Sander Versluys Avatar asked Apr 27 '12 13:04

Sander Versluys


3 Answers

You can easily do this with

getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>App Name</font>"));
like image 185
Ajmal Salim Avatar answered Nov 03 '22 13:11

Ajmal Salim


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.

like image 44
adneal Avatar answered Nov 03 '22 14:11

adneal


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.

like image 24
shontauro Avatar answered Nov 03 '22 15:11

shontauro