Search code examples
androidandroid-layoutandroid-popupwindow

android - How to design a pop-up window having rounded corners and shadows


Before marking this as duplicate, I'd like to say that I have gone through SO posts like this, this and this. But I haven't found any solution suitable to me.

I am trying to create a pop-up window using PopupWindow(). I want to design this window using rounded corners and dropback shadows (like shadows under a FloatingActionButton).

I have come across solutions like defining a shape with rounded corners and then using it as a background. But there is this problem with this solution.

This doesn't work. as you've set, it's the background, so the content overrides the rounded corners, and if you have content that draws on the corners, you won't see them being rounded. - (posted here)

I assume this is not an ideal solution. There was also another solution of creating a Custom Layout class as provided on the second link. But using that I faced a few problems like my EditText within this layout was not updating it's text inside while typing. It is being updated once I close the keyboard. Moreover, this solution also has some performance issues.

There was no real helpful SO posts on designing a pop-up window in android. I'd like to know if there are standard ways to do this effectively and if that is even possible.

For shadow effects, I saw this post, and tried the different solutions it offered. But they gave me very different results across devices. I would also like to know if there is a possible standard and effective solution.

Please help. Thank you.


Solution

  • create a 9 patch background like so:

    enter image description here

    content padding will not let it spread outside corners.