Actionbar Sherlock更改标题颜色

时间:2012-12-21 11:07:40

标签: android android-actionbar actionbarsherlock android-theme

我正在尝试主题Sherlock Action Bar。我想将标题的颜色设置为白色。当我尝试执行以下操作时,标题会一起消失。

另外,我想在按下时更改动作项目图标的背景颜色。

我尝试了什么?

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Variation on the Holo Light theme that styles the Action Bar -->
    <style name="Theme.Nomad" parent="Theme.Sherlock.Light">
        <item name="actionBarStyle">@style/Widget.Nomad.ActionBar</item>
        <item name="android:actionBarStyle">@style/Widget.Nomad.ActionBar</item>
        <item name="android:actionBarItemBackground">@drawable/actionbar_selectable_background</item>
        <item name="actionBarItemBackground">@drawable/actionbar_selectable_background</item>
        <item name="android:titleTextStyle">@style/TitleText</item>
        <item name="titleTextStyle">@style/TitleText</item>

        <!--
        <item name="android:popupMenuStyle">@style/MyPopupMenu</item>
        <item name="popupMenuStyle">@style/MyPopupMenu</item>

        <item name="android:dropDownListViewStyle">@style/MyDropDownListView</item>
        <item name="dropDownListViewStyle">@style/MyDropDownListView</item>

        <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
        <item name="actionBarTabStyle">@style/MyActionBarTabStyle</item>

        <item name="android:actionDropDownStyle">@style/MyDropDownNav</item>
        <item name="actionDropDownStyle">@style/MyDropDownNav</item>

        <item name="android:listChoiceIndicatorMultiple">@drawable/ad_btn_check_holo_light</item>
        <item name="android:listChoiceIndicatorSingle">@drawable/ad_btn_radio_holo_light</item>

        <item name="android:actionOverflowButtonStyle">@style/MyOverflowButton</item>


        -->
    </style>

    <style name="Widget.Nomad.ActionBar" parent="Widget.Sherlock.ActionBar">
        <item name="android:background">#E5492A</item>
        <item name="background">#E5492A</item>
    </style>

    <style name="TitleText" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
        <item name="android:textColor">@android:color/white</item>
        <item name="textColor">@android:color/white</item>
        <item name="android:textSize">18dip</item>
        <item name="textSize">18dip</item>
    </style>

</resources>

2 个答案:

答案 0 :(得分:6)

我不确定项目背景,但对于文字颜色,你可以:

  • 在Widget.Nomad.ActionBar中添加这些项目(带有父Widget.Sherlock.ActionBar的样式):

    <item name="android:titleTextStyle">@style/TitleText</item>
    <item name="titleTextStyle">@style/TitleText</item>
    
  • 其中:

    <style name="TitleText" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
        <item name="android:textColor">@android:color/white</item>
        <item name="android:textSize">18sp</item>
    </style>
    

答案 1 :(得分:4)

最好的解决方案是这个!

actionBar.setTitle(Html.fromHtml("<font color=\"#ffffff\"><b>" + AppName + "</b></font>"));

我保证会非常有帮助!祝你好运!