android 如何更改溢出菜单的背景颜色

How to change the background color of the overflow menu in android

我想更改溢出弹出菜单的背景颜色以匹配主屏幕的背景。有谁知道我该怎么做?
谢谢

如果您使用的是工具栏,首先您需要将此行添加到您的工具栏布局中:

app:popupTheme="@style/ThemeOverlay.MyTheme"

它应该是这样的:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/primary"
    app:titleTextColor="@color/white"
    app:layout_scrollFlags="scroll|enterAlways"
    app:popupTheme="@style/ThemeOverlay.MyTheme"/>

您需要使用该行来告诉您的工具栏要使用哪个主题。然后,将以下主题添加到 styles.xml 文件中:

<style name="ThemeOverlay.MyTheme" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:colorBackground">@color/primary</item>
    <item name="android:textColor">@color/white</item>
</style>

在我放“@color/primary”和“@color/white”的地方,你可以用任何你想要的颜色,也可以放#000000这样的十六进制值。