Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change popupmenu background color when using support library

I'm trying to change the background color of a popup menu in the actionbar, when using Android Support Library v7. I've been trying various suggested solutions that I've found, but none of them have worked, the popup menu background simply doesn't change from the theme's standard color. This is what I've done so far:

AndroidManifest:

android:theme="@style/MyTheme" >

values/themes.xml:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="MyTheme" parent="@style/Theme.AppCompat">
        <item name="popupMenuStyle">@style/MyPopupMenu</item>
    </style>

    <style name="MyPopupMenu" parent="@style/Widget.AppCompat.PopupMenu">
        <item name="background">#ffffff</item>
    </style>

</resources>

The values-11 and values-14 folders also have a theme file each, with the difference that the popupMenuStyle and background attributes are instead written as android:popupMenuStyle and android:background, since they aren't supposed to use the support library.

Thanks in advance.

like image 860
jomni Avatar asked Jan 03 '14 18:01

jomni


People also ask

How do I change the background color of a menu item?

Open the colors. xml file by navigating to the app -> res -> values -> colors. xml. Create a color tag inside the resources tag with a name and set a color with its hex code.

Which option of the pop up menu should we click to change the wallpaper?

Which option of the pop up menu should we click to change the wallpaper? On the Themes tab, under Theme Options, click Background. On the pop-up menu, click Format Background.

How do I use pop up menu on Android?

Go to app > res > right-click > New > Android Resource Directory and give Directory name and Resource type as menu. Now, we will create a popup_menu file inside that menu resource directory. Go to app > res > menu > right-click > New > Menu Resource File and create a menu resource file and name it as popup_menu.


1 Answers

in your style.xml add popupMenuStyle like this:

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="popupMenuStyle">@style/popupMenuStyle</item>     
</style>
<style name="popupMenuStyle" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@color/white</item>
</style>
like image 141
Alexandr Tutkevich Avatar answered Oct 24 '22 05:10

Alexandr Tutkevich