2013-07-04 177 views
14

我想自定義我的android應用程序的actionBar。
我正在使用Actionbar Sherlock。
我的分目標SDK是14,目標SDK 17
我有改變背景顏色和主標題文本主題
但我不能改變
我的風格,在這裏顯示的字幕文本顏色

更改Android操作欄字幕顏色

<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> 


有什麼做錯了?

回答

21

只要改變titleTextStylesubtitleTextStyle

<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> 
+3

,使該標題風格的字幕。字幕樣式應該從'@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle'繼承。 – MemoryLeak

0

我結束了這一點(它更接近我所需要的)

@style/Widget.Styled.ActionBar @style/Widget.Styled.ActionBar

<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar.Solid"> 
    <item name="subtitleTextStyle">@style/TextAppearance.Sherlock.Widget.Styled.ActionBar.Subtitle</item> 
    <item name="android:subtitleTextStyle">@style/TextAppearance.Sherlock.Widget.Styled.ActionBar.Subtitle</item> 
    <item name="android:background">#8B0000</item> 
</style> 

<style name="TextAppearance.Sherlock.Widget.Styled.ActionBar.Subtitle" parent="Widget"> 
    <item name="android:textSize">12sp</item> 
</style> 

<style name="OverFlow" parent="Widget.Sherlock.ActionButton.Overflow"> 
    <item name="android:src">@drawable/abs__ic_menu_moreoverflow_holo_light</item> 
</style> 


2

幾乎沒有。這裏是代碼:

<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:subtitleTextStyle">@style/MyTheme.ActionBar.Subtitle</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> 
+0

萬一你得到一個API級別13的警告 - 只需使用(對於TitleTextStyle和Subtitle)@ android/style/TextApperance爲父級。 –

3

這組樣式格式化操作欄,包括背景,標題和副標題文本;它也能格式化選項卡,包括所有狀態(選擇,非選擇,並且所有的聚焦/按壓的組合),以及標籤文本字體和大小(每Android開發指令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> 

這組樣式看起來特別好,當drawables使用一些連貫的顏色值(例如薰衣草爲紫色選擇,紫色爲薰衣草爲未選中,將值更改爲黑色以便按下和聚焦更輕)時,漸變色。

0

添加下面的代碼在你的活動文件

actionBar.setSubtitle(Html.fromHtml("<font color='#FFBF00'>Here ActionBar Subtitle</font>"));