Android Actionbar子菜单项背景

Android Actionbar子菜单项背景,android,menu,actionbarsherlock,Android,Menu,Actionbarsherlock,我正在我的应用程序中使用ActionBar sherlock库 如何更改ActionBar子菜单列表项背景我应该在样式中使用什么属性?演示如何设置ABS下拉项的样式。您可以从查看res/values/styles.xml并更改下拉项样式开始 <style name="Theme.MyApp" parent="Theme.Sherlock.Light"> <!-- the text when loading --> <!-- <item

我正在我的应用程序中使用ActionBar sherlock库 如何更改ActionBar子菜单列表项背景我应该在样式中使用什么属性?

演示如何设置ABS下拉项的样式。您可以从查看res/values/styles.xml并更改下拉项样式开始

<style name="Theme.MyApp" parent="Theme.Sherlock.Light">
    <!--  the text when loading -->
    <!--
    <item name="actionBarStyle">@style/Widget.MyApp.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.MyApp.ActionBar</item>
    -->

    <!-- the dropdown items -->
    <item name="android:spinnerDropDownItemStyle">@style/MyApp.Widget.Holo.DropDownItem</item>
    <item name="spinnerDropDownItemStyle">@style/MyApp.Widget.Holo.DropDownItem</item>

    <!--  the action bar dropdown menu item -->
    <!-- 
    <item name="android:spinnerItemStyle">@style/MyApp.Widget.Holo.SpinnerItem</item>
    <item name="spinnerItemStyle">@style/MyApp.Widget.Holo.SpinnerItem</item>
    -->
</style>

@style/MyApp.Widget.Holo.DropDownItem
@style/MyApp.Widget.Holo.DropDownItem

基本上,您需要通过在
style.xml
中使用自定义的
颜色/可绘制选择器覆盖
android:itemBackground
属性来定制
菜单项的样式

如果您的菜单也有
子菜单
,那么您还需要设置子菜单的
标题
的样式,通常通过使用
自定义样式
覆盖属性
actionBarPopupTheme
自动设置为白色背景

style.xml

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
        <item name="android:itemBackground">@drawable/menu_popup_selector</item>
        <item name="actionBarPopupTheme">@style/SubmenuHeaderStyle</item>
    </style>

    <style name="SubmenuHeaderStyle" parent="ThemeOverlay.AppCompat.Light">
        <item name="android:colorBackground">@color/colorAccent</item>
    </style>

</resources>

@可绘图/菜单\弹出\选择器
@样式/子菜单标题样式
@颜色/颜色重音
菜单\弹出\选择器.xml

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <color
            android:color="@color/colorPrimary"/>
    </item>
    <item>
        <color
            android:color="#655611"/>
    </item>
</selector>

您将看到类似于此屏幕截图的内容(粉色标题是我的子菜单标题)

只是想让您知道,当我没有子菜单的普通菜单看起来像以下层次视图:

<menu> 
   <item/>
   <item/> 
   <item/> 
</menu> 

以及具有子菜单的菜单,作为层次视图的示例:

<menu> 
   <item/>
   <item/>
   <group> 
     <item> 
       <menu> 
         item 
         item 
         item 
       </menu> 
     </item>
   </group>
   <item/>
   <item/> 
</menu>

项目
项目
项目