s89aduasda
s89aduasda

Reputation: 231

Android PopupWindow: White background but keep shadow?

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

Objective

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

White content background

Which has a shadow but still has the black "border" which really is just the uncovered parts of the popup window background.

So I try and set the popup window background to white with:

popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE))

which causes this:

which gives the correct background colour but also removes the shadow.

So is there any easy way to keep the shadow but set the background as white. Is there something else I should use instead of PopupWindow to create what I want? Or do I have to use a 9 patch or something?

Upvotes: 9

Views: 7198

Answers (3)

KrzyShzy
KrzyShzy

Reputation: 156

If nothing works, you can use below code. This will place a shadow around Popupwindow with white background. I've tested it in my app.

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

Upvotes: 3

fabelYu
fabelYu

Reputation: 41

after set background,just add elevation.

popupWindow.setElevation(10);

this will work after API21.

Upvotes: 4

s89aduasda
s89aduasda

Reputation: 231

I just ended up using a 9 patch created with http://inloop.github.io/shadow4android/

Upvotes: 13

Related Questions