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

时间:2017-04-01 14:34:17

标签: android android-actionbar overflow background-color

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

1 个答案:

答案 0 :(得分:15)

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

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这样的十六进制值。

相关问题