2014-12-05 68 views
0

我想将自定义背景添加到AppCompat操作栏。这是我的风格禁用操作栏的默认背景并添加自定义背景

<!-- 
    Base application theme, dependent on API level. This theme is replaced 
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
--> 
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"> 
    <item name="android:actionBarStyle">@style/MyActionBar</item> 
    <!-- 
     Theme customizations available in newer API levels can go in 
     res/values-vXX/styles.xml, while customizations related to 
     backward-compatibility can go here. 
    --> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
</style> 

<!-- ActionBar styles --> 
<style name="MyActionBar" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="android:background">@drawable/top_bar_bg</item> 
</style> 

我使用AppTheme我的主题。它仍然显示默认的黑暗背景。我在这里错过了什么?

回答

0

在RES /价值/ styles.xml:

<?xml version="1.0" encoding="utf-8"?> 
    <resources> 
     <!-- the theme applied to the application or activity --> 
     <style name="CustomActionBarTheme" 
       parent="@style/Theme.AppCompat.Light.DarkActionBar"> 
      <item name="actionBarStyle">@style/MyActionBar</item> 
     </style> 

     <!-- ActionBar styles --> 
     <style name="MyActionBar" 
       parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
      <item name="background">@drawable/actionbar_background</item> 
     </style> 
    </resources> 

在res /值-V11/styles.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <!-- the theme applied to the application or activity --> 
    <style name="CustomActionBarTheme" 
      parent="@style/Theme.AppCompat.Light.DarkActionBar"> 
     <item name="android:actionBarStyle">@style/MyActionBar</item> 
    </style> 

    <!-- ActionBar styles --> 
    <style name="MyActionBar" 
      parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
     <item name="android:background">@drawable/actionbar_background</item> 
    </style> 
</resources> 
+0

试过更换仍然没有工作 – 2014-12-05 11:43:50

+0

您是否使用了最新的更新支持库v7的?如果是,那么现在通过Material Design可以使用'android:colorPrimary'属性指定动作栏颜色。 – 2014-12-05 11:47:08