Android PopupWindow: white background, but keep the shadow?

How do I create a PopupWindow in Android with a white background, but still keep the shadow? I am trying to create something like this :

Objective

By default, my PopupWindow has a dark background. So I set the contents of the popup to a white background, which this gives me:

White content background

Which has a shadow, but still has a black β€œborder,” which is actually just the uncovered parts of the pop-up background.

So, I'm trying to set the background of the popup to white using "popupWindow.setBackgroundDrawable (new ColorDrawable (Color.WHITE)" that calls this :

which gives the correct background color, but also removes the shadow.

So, is there an easy way to keep the shadow, but set the background to white. Is there anything else I should use instead of PopupWindow to create what I want? Or do I need to use 9 patches or something else?

+5
source share
3 answers

I just finished using 9 patches created using http://inloop.imtqy.com/shadow4android/

+10
source

after the given background, just add a mark.

popupWindow.setElevation(10); 

this will work after API21.

+1
source

If nothing works, you can use the code below. This will create a shadow around the Popupwindow with a white background. I tested it in my application.

 popupWindow.setBackgroundDrawable(context.getDrawable(android.R.drawable.picture_frame)); 
0
source

Source: https://habr.com/ru/post/1216122/


All Articles