Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the background color of the overflow menu in 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.

like image 374
Rob26br Avatar asked Apr 01 '17 14:04

Rob26br


1 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.

like image 124
Rob Avatar answered Oct 17 '22 06:10

Rob