如何更改选项菜单背景颜色

时间:2021-06-09 13:07:32

标签: android

我正在尝试更改选项菜单背景,但顶部和底部有空白
我的工具栏样式

 app:popupTheme="@style/ThemeOverlay.MyTheme"
   <style name="ThemeOverlay.MyTheme" parent="ThemeOverlay.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>

        <!-- To change the popup menu and app text color  -->
        <item name="android:textColor">@color/white</item>

        <!-- To change the background of options menu-->
        <item name="android:itemBackground">@color/black</item>
    </style>

示例:

enter image description here

2 个答案:

答案 0 :(得分:0)

您在搜索this吗?

在您的应用程序样式中为菜单创建样式,并在您的应用程序主题中添加该条目 不要忘记在您的menifest 的应用程序标签中添加该主题

android:theme="@style/AppTheme"

答案 1 :(得分:0)

材质主题有问题

 <style name="Theme.MyApplication" parent="Theme.AppCompat.DayNight.DarkActionBar">
        <item name="android:itemBackground">@color/bluish_green</item>
    </style>

    <style name="ThemeOverlay.MyTheme" parent="Theme.MyApplication">
        <!-- To change the popup menu and app text color  -->
        <item name="android:textColor">@color/white</item>
        <!-- To change the background of options menu-->
        <item name="android:itemBackground">@color/black</item>
        <item name="android:popupBackground">@color/black</item>
        <item name="android:drawablePadding">0dp</item>
        <item name="android:dividerHeight">1dp</item>

    </style>