1

This has been posted many times, but none of the existing solution appears to work with API 21+. The default popup's background color is exactly the same as the default background color for the layouts.

This is what it looks like (The popup is over a gridview but it has no obvious 'boundary' which looks a little off)

Something like this is ideal,i.e, with a proper material design shadow. There's a solution for accomplishing this with the toolbar popup menu. Not with a 'normal' PopupMenu.

This old question is trying to accomplish the same, however the given solution now no longer works:

<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle">@style/popupMenuStyle</item>
</style>
<style name="popupMenuStyle" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@color/bgPopumMenu</item>
</style>

And neither does setting a custom context wrapper:

 Context wrapper = new ContextThemeWrapper(getContext(), R.style.PopupMenu);
 PopupMenu popup = new PopupMenu(wrapper, anchorView);

So, I'm unable to even change the background color of the popupmenu, let alone have a proper material design shadow.

How to give PopupMenu a shadow? Or how do I at least use a custom background drawable (using which I could put in a 9 patch shadow)

Community
  • 1
  • 1
Aditya Anand
  • 776
  • 2
  • 9
  • 29

2 Answers2

3

You need a separate style for Lollipop+.
Create another resource: res/values-v21/styles.xml.
Add there Your popup style and specify needed elevation:

<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
    <item name="android:popupBackground">@android:color/white</item>
    <item name="android:popupElevation">20dp</item>
</style>

That's it.

Leo DroidCoder
  • 14,527
  • 4
  • 62
  • 54
1

Add popupMenu style to ur AppTheme: @style/PopupMenu

<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
    <item name="android:popupBackground">@android:color/white</item>
</style>

manifest.xml:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
.............
</application>

PS: Answer taken from here

Community
  • 1
  • 1