如何在Android中更改溢出菜单的背景色 [英] How to change the background color of the overflow menu in android

查看:141
本文介绍了如何在Android中更改溢出菜单的背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to change the background color of the overflow popup menu to match the background of the main screen. Does anyone know how I could do that?
Thanks.

推荐答案

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

If you are using a Toolbar, first you need to add this line to your toolbar layout:

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文件中:

You need to use that line to tell your Toolbar which theme to use. Then, you add the following theme to your styles.xml file:

<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等十六进制值.

In the place I put "@color/primary" and "@color/white", you can use any color you want, and you can also put hex values like #000000.

这篇关于如何在Android中更改溢出菜单的背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆