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

醉酒当歌 提交于 2019-12-23 08:45:28

问题


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.


回答1:


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

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

It should look like this:

<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"/>

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>

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.



来源:https://stackoverflow.com/questions/43158160/how-to-change-the-background-color-of-the-overflow-menu-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!