ActionBar样式不起作用

时间:2015-03-27 05:25:51

标签: android android-actionbar android-styles

以下是我正在申请的款式:

 <style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="android:windowNoTitle">true</item>
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.MY_STYLE</item>
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>  

<style name="ActionBarTabStyle.MY_STYLE" parent="@style/Widget.AppCompat.Light.ActionBar.TabView">
    <item name="android:paddingLeft">1dip</item>
    <item name="android:paddingRight">1dip</item>
    </style>  
<style name="MyActionBar" parent="Theme.AppCompat.Light">
        <item name="android:background">#ffffff</item>
    </style>  

但这两种风格都不起作用。 ActionBar标签的宽度都没有减少,ActionBar的背景颜色也没有变化。

2 个答案:

答案 0 :(得分:1)

你能试试吗?

  <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabTextStyle">@style/MyTitleTextStyle</item>
    <item name="android:actionMenuTextColor">@color/wheat</item>
    <item name="android:actionMenuTextAppearance">@style/MyTitleTextStyle</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
    <item name="actionBarTabTextStyle">@style/MyTitleTextStyle</item>
    <item name="actionMenuTextColor">@color/wheat</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="actionMenuTextAppearance">@style/MyTitleTextStyle</item>
</style>

<style name="MyTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/wheat</item>
    <item name="android:textSize">21sp</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
    <item name="android:titleTextStyle">@style/MyTitleTextStyle</item>
    <item name="android:backgroundSplit">@drawable/actionbar_dr</item>
    <item name="android:background">@drawable/actionbar_dr</item>

    <!-- Support library compatibility -->
    <item name="titleTextStyle">@style/MyTitleTextStyle</item>
    <item name="background">@drawable/actionbar_dr</item>
    <item name="backgroundSplit">@drawable/actionbar_dr</item>
</style>

并记住在values-v11values-v14 style.xml

中添加此样式

在我的案例中,它是完美的工作。

enter image description here

将此drawable设为Action Bar背景

 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true"><shape>
        <solid android:color="#449def" />

        <stroke android:width="1dp" android:color="#2f6699" />

    </shape></item>
<item><shape>
        <gradient android:angle="270" android:endColor="#2f6699" android:startColor="#449def" />

        <stroke android:width="1dp" android:color="#2f6699" />

    </shape></item>

 </selector>

答案 1 :(得分:1)

我认为android:background属性(在ActionBarStyle中)并不是故事的颜色,而是只有可绘制的资源(据说,我仍然无法改变动作栏的颜色)