Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the text color of action bar sherlock

I know there are very few questions already posted on this thing. I filtered almost every post, but no luck and I am not getting the result which I have to get. First I tried code snippet#1, everything worked fine as in the image1. But now I must change the actionbar background to light and dull color, so did it, the result is activity's title and items' titles are in white color which are barely legible. So, decided to change the text color, but didn't get how to change it with my present code in the styles.xml. If someone could help me in changing the text color with present code(snippet#1) itself, that would be very great. As I didn't get how to modify the present code, I Followed this and so now my code is code snippet#2, now my action bar completely goes weird making the home icon and app title disappear and displays only the item that is towards right like the image 2. Can someone please help me resolve this issue?

code snippet#1

<style name="MyTheme" parent="Theme.Sherlock">
    <item name="actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:windowBackground">@color/white</item>
</style>

<style name="MyActionBar" parent="Widget.Sherlock.ActionBar">
    <item name="background">@drawable/action_bar_background</item>
    <item name="android:background">@drawable/action_bar_background</item>
</style>

code snippet#2

<style name="MyTheme" parent="Theme.Sherlock.Light">
        <item name="actionBarStyle">@style/CustomActionBar</item>
    </style>

    <style name="CustomActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
         <item name="android:background">@drawable/action_bar_background</item>
         <item name="titleTextStyle">@style/ActionBarTitle</item>
    </style>

    <style name="ActionBarTitle" parent="@android:style/TextAppearance.Medium">
        <item name="android:textColor">#000000</item>
    </style>

Below are my images:

enter image description here

enter image description here

In the second image, title, icon and blue border line are disappeared. I have to show them because I am setting home enabled to true.

like image 242
Korhan Avatar asked Nov 28 '22 09:11

Korhan


2 Answers

This is the most recommended for customizing an ActionBar:

http://jgilfelt.github.com/android-actionbarstylegenerator/

its easy too.

If you only want to change some Text color/size, try this:

<?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>
        <item name="android:textSize">@dimension/MEDIUM_TEXT</item>
        <item name="textSize">@dimension/MEDIUM_TEXT</item>
    </style>
</resources>
like image 182
Archie.bpgc Avatar answered Dec 16 '22 01:12

Archie.bpgc


I used the link above from Archie.bpgc and created a style that used the Light - Dark Action Bar and that solved my problem by allowing me to pick the colors that I needed.

The above example did not work for me to change the text color.

The link: http://jgilfelt.github.com/android-actionbarstylegenerator/

like image 34
Ray Hunter Avatar answered Dec 16 '22 01:12

Ray Hunter