Home » Android » How to change the background color of the overflow menu in android

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

Posted by: admin June 15, 2020 Leave a comment

Questions:

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.

How to&Answers:

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.