为什么此 XML 代码不为 Android 4.3 中溢出菜单的背景着色?



我正在尝试为弹出菜单上色(当点击溢出的三个垂直点时),但它不起作用:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:popupMenuStyle">@style/MyPopupMenu</item>
        <!-- None of these work either -->
        <item name="android:windowBackground">@color/white</item>
        <item name="android:popupBackground">@color/white</item>
        <item name="android:actionModeBackground">@color/white</item>
        <item name="android:dropDownListViewStyle">@style/MyPopupMenu</item>
        <item name="android:actionBarWidgetTheme">@style/MyPopupMenu</item>
    </style>
    <!-- Popup Menu Background Color styles -->
    <!--
        I also tried parent as:
              android:Widget.Holo.Light.ListPopupWindow
              @style/Widget.AppCompat.Light.ListPopupWindow
              @android:style/Widget.Holo.ListPopupWindow
    -->
    <style name="MyPopupMenu"
    parent="@android:style/Widget.PopupMenu">
    <item name="android:popupBackground">@android:color/white</item>
    </style>
</resources>

在我的AndroidManifest.xml中:

 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

为什么它仍然以默认的黑色背景显示?

确保您已根据版本应用样式。。。

values.xml更换

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

值-14.xml

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

尝试一次。。。

相关内容

  • 没有找到相关文章