Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Android Actionbar subtitle colour

I wish to customize the actionBar of my android application.
I am using Actionbar Sherlock.
My min target sdk is 14, target sdk 17.
I have a theme that changes the background colour and main title text
however i cannot change the subtitle text colour
my style is shown here

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    <item name="android:background">#8B0000</item>
</style>

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">#FFFFFF</item>

</style>

<style name="MyTheme.ActionBar.Subtitle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">
    <item name="android:textColor">#FF0000</item>

</style>


what have a done wrong?

like image 601
Hector Avatar asked Jul 04 '13 20:07

Hector


People also ask

How do you change the color of your title on Android?

in your style. 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.


2 Answers

Just change titleTextStyle to subtitleTextStyle

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
  </style>

  <style name="MyTheme.ActionBarStyle"parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
  </style>

  <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/red</item>
  </style>
like image 139
Androiderson Avatar answered Oct 23 '22 06:10

Androiderson


This set of styles formats the action bar, including background, title and subtitle text; it also formats the tabs, including all states (selected, unselected, and all the focused/pressed combinations), as well as the tab text font and size (per Android developers instruction https://developer.android.com/training/basics/actionbar/styling.html):

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/themeActionBar</item>
    <item name="android:actionBarTabTextStyle">@style/styleActionBarTabText</item>
    <item name="android:actionMenuTextColor">@color/actionbar_text</item>
    <item name="android:actionBarTabStyle">@style/styleActionBarTabs</item>
    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/themeActionBar</item>
    <item name="actionBarTabTextStyle">@style/styleActionBarTabText</item>
    <item name="actionMenuTextColor">@color/actionbar_text</item>
    <item name="actionBarTabStyle">@style/styleActionBarTabs</item>
</style>

<!-- ActionBar styles -->
<style name="themeActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/abactionbargradient</item>
    <item name="android:titleTextStyle">@style/styleActionBarTitleText</item>
    <item name="android:subtitleTextStyle">@style/styleActionBarSubTitleText</item>
    <!-- Support library compatibility -->
    <item name="background">@drawable/abactionbargradient</item>
    <item name="titleTextStyle">@style/styleActionBarTitleText</item>
    <item name="subtitleTextStyle">@style/styleActionBarSubTitleText</item>
</style>

<!-- ActionBar title text -->
<style name="styleActionBarTitleText"
    parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/actionbar_title_text</item>
    <!-- The textColor property is backward compatible with the Support Library -->
</style>

<!-- ActionBar title text -->
<style name="styleActionBarSubTitleText"
    parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle">
    <item name="android:textColor">@color/actionbar_sub_title_text</item>
    <!-- The textColor property is backward compatible with the Support Library -->
</style>

<!-- ActionBar tabs text -->
<style name="styleActionBarTabText"
    parent="@style/Widget.AppCompat.ActionBar.TabText">
    <item name="android:textColor">@color/actionbar_text</item>
    <item name="android:textSize">10dp</item>
    <!-- The textColor property is backward compatible with the Support Library -->
</style>

<!-- ActionBar tabs styles -->
<style name="styleActionBarTabs"
    parent="@style/Widget.AppCompat.ActionBar.TabView">
    <!-- tab indicator -->
    <item name="android:background">@drawable/abactionbartabs</item>

    <!-- Support library compatibility -->
    <item name="background">@drawable/abactionbartabs</item>
</style>

This set of styles looks especially nice when the drawables are gradients using some set of coherent color values (i.e. lavender to purple for selected and purple to lavender for unselected, changing the values to darker for pressed and lighter for focused).

like image 21
StephenDonaldHuffPhD Avatar answered Oct 23 '22 05:10

StephenDonaldHuffPhD