Android PopupWindow: White background but keep shadow?
NickName:s89aduasda Ask DateTime:2015-03-26T03:13:40

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?

Copyright Notice:Content Author:「s89aduasda」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/29264523/android-popupwindow-white-background-but-keep-shadow

Answers
s89aduasda 2015-03-27T01:24:47

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


fabelYu 2017-02-15T03:25:22

after set background,just add elevation.\n\npopupWindow.setElevation(10);\n\n\nthis will work after API21.",


More about “Android PopupWindow: White background but keep shadow?” related questions

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]: By default, my PopupWindow has a dark background. So I s...

Show Detail

Remove shadow in Android PopupWindow

I have created my PopupWindow using a simple LinearLayout with a background color. There is a shadow on the PopupWindow. How do I remove the shadow automatically generated for the PopupWindow. I

Show Detail

Android Popup Menu Shadow

I created this popup menu but the background shadow is missing. How can I add some? It would be cool if the shadow is only on the left and the bottom. Here is a picture: You can see that the color...

Show Detail

How to set background color of exposed dropdown PopupWindow?

I'm using an exposed dropdown from material design components. It's an AutoCompleteTextView within a TextInputLayout which basically acts like a spinner. You give it an adapter and it pops up a

Show Detail

Android : My PopupWindow's background is transparent

I created a PopupWindow like this : PopupWindow popupWindow = new PopupWindow(LayoutInflater.from(this).inflate(R.layout.main_popup_navigation, null, false), ViewGroup.LayoutParams.WRAP_CONTENT,

Show Detail

Popupwindow with layout shadow

I'm looking for PopupWindow with layout shadow, but I cannot see it. I want to do my PopupWindow with a little dim such as bottom sheet or dialog.

Show Detail

Android PopupWindow elevation does not show shadow

Android PopupWindow does not show shadows when the elevation is set. It appears to support it from the documentation. I am using 5.0 Lollipop. Creating the popup as follows: popupWindow =...

Show Detail

Android PopupWindow elevation does not show shadow

Android PopupWindow does not show shadows when the elevation is set. It appears to support it from the documentation. I am using 5.0 Lollipop. Creating the popup as follows: popupWindow =...

Show Detail

Android PopupWindow elevation does not show shadow

Android PopupWindow does not show shadows when the elevation is set. It appears to support it from the documentation. I am using 5.0 Lollipop. Creating the popup as follows: popupWindow =...

Show Detail

PopupWindow background disappears. It becomes transparent automatically

I am showing a PopupWindow and setting its background as 9 patch image. PopupWindows background becomes transparent when it becomes visible. I am unable to find out issue. How should it be resolved...

Show Detail