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 change the background color of the overflow menu in android
Asked Answered
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.
I'm glad to help! –
Coorg
check this for material/appcompat v21 solution https://mcmap.net/q/1014353/-how-to-change-the-background-color-of-dropdown-menu-in-the-actionbar –
Profiteer
What if we have a menu inside the menu like menu->item->menu. So above approach change background color for first menu items but not for submenus –
Hermes
© 2022 - 2024 — McMap. All rights reserved.