Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionbar Compat change title textColor

I am trying to modify the text color of the title of the ActionBarSupport. I have used ActionBarStyleGenererator to create a theme with the correct colors and it works well.

While using the light theme, I would like to change the color of the heading to white (in the genererator I cannot set the text color(. For a number of reasons I cannot use the dark actionbar theme. I am so close, just have to get the title to white ;-)

What I am doing wrong here?

<style name="ActionBar.Transparent.MyApp" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="background">@drawable/ab_transparent_myapp</item>
    <item name="progressBarStyle">@style/ProgressBar.MyApp</item>
    <item name="titleTextStyle">@style/MyApp.TitleTextStyle</item>  
</style>

 <style name="MyApp.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.Base.ActionBar.Title">
    <item name="android:textColor">#ffffff</item>    
 </style>
like image 573
jannej Avatar asked Dec 06 '13 15:12

jannej


People also ask

How do I change the color of my action bar title?

xml in values folder this will change your action bar color.. Replace #666666 with your selected color code for title background color and replace #000000 for your title text color.

How can I customize my action bar in Android?

This example demonstrate about how to create a custom action bar in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I change the text color on my Android toolbar?

Go to the app > res > values > themes > themes. xml file and add the following line inside the <resources> tag. In the activity's onCreate() method, call the activity's setSupportActionBar() method, and pass the activity's toolbar.


3 Answers

The below code worked for me. I hope it will help you tooo.

<style name="AppTheme" parent="AppBaseTheme">
        <item name="actionBarStyle">@style/ActionBarCompat</item>
    </style>

    <style name="ActionBarCompat" parent="@style/Widget.AppCompat.Base.ActionBar">
        <item name="titleTextStyle">@style/titleStyle</item>
    </style>

    <style name="titleStyle" parent="@style/TextAppearance.AppCompat.Widget.Base.ActionBar.Title">
        <item name="android:textColor">@android:color/white</item>
    </style>
like image 188
TNR Avatar answered Sep 23 '22 00:09

TNR


Embarrassing. I was not paying attention to the values-v14/-folder (which overrides the vales/) ActionBarStyleGenererator created. Using the android-prefix on the styles in values-v14 it worked:

      <item name="android:titleTextStyle">@style/titleTextStyle</item>
like image 39
jannej Avatar answered Sep 23 '22 00:09

jannej


Found at Overflow styling

I've been trying to keep the ActionBar title text color through orientation changes without much luck until I got a clue from the above site. I applied the Spannable to to the title. Here's what i do when setting up my ActionBar:

    Spannable actionBarTitle = new SpannableString("Action Bar Title");
    actionBarTitle.setSpan(
            new ForegroundColorSpan(Color.WHITE),  
            0, 
            actionBarTitle.length(), 
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    mActionBar.setTitle(actionBarTitle);

This needs to be executed on orientation change. I call it from onCreate()...don't know if it works in onConfigurationChange().

like image 35
David S Alderson Avatar answered Sep 20 '22 00:09

David S Alderson