如何在Android中设置溢出菜单的背景颜色?

时间:2014-11-17 15:36:17

标签: android menu android-actionbar

我正在尝试为溢出菜单设置自定义背景颜色。但是,我无法这样做。这就是我试过的:

<resources>

<style name="TranslucentTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/TranslucentActionBar</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>

<style name="PopupMenu" parent="@android:Widget.Holo.Light.PopupWindow">
    <item name="android:popupBackground">@color/transparent_black</item>
</style>

<style name="TranslucentActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@null</item>
    <item name="android:logo">@drawable/actionbar_logo_space</item>
</style>

</resources>

我做错了什么?

1 个答案:

答案 0 :(得分:0)

试试这个:

1)向DropDownListView添加样式:

<style name="OdnakoDropDownListView" parent="@android:Widget.Holo.ListView.DropDown">
        <item name="android:listSelector">@drawable/selectable_background</item>
        <item name="android:background">@android:color/black</item>
        <item name="actionMenuTextColor">@android:color/white</item>
</style>

2)在yours / res / drawable中创建selectable_background.xml

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

    <item android:drawable="@drawable/list_focused" android:state_focused="true" android:state_pressed="false"/>
    <item android:drawable="@drawable/ic_launcher" android:state_pressed="true"/>
    <item android:drawable="@android:color/blue"/>

</selector>

3)将项目添加到您的主题:

<style name="TranslucentTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- other attributes-->
<item name="android:dropDownListViewStyle">@style/OdnakoDropDownListView</item>
</style>