zawadz88 / MaterialPopupMenu

Shows Material popup menus grouped in sections & more
Apache License 2.0
646 stars 57 forks source link

Fix background clipping when using rounded corners #47

Closed Tunous closed 5 years ago

Tunous commented 5 years ago

This change allows users to use custom items that have colored background and also use a popup with rounded corners.

Before the changes, the popup wouldn't display rounded corners for the custom view because its background wasn't clipped and it was drawing outside of the area of rounded drawable. After the change, when drawing, the content is properly clipped to the area of the background drawable and thus rounded corners work correctly.


I've also added sample for the rounded corners but unfortunately you can't see in it how I've fixed the corners issue. That's because the default view adds top and bottom padding which prevents the item from appearing at the edge of popup where the issue would be present. Although, that can be fixed if #44 gets merged so we can then set that vertical padding to 0.

Anyway here is how it looks right now:

Tunous commented 5 years ago

This change basically makes it possible to implement background like this:

Note that this screenshot uses features from all my pull requests combined 😄

Tunous commented 5 years ago

Good finds. I usually don't support these earlier versions of Android in my apps anymore so I forgot to test on them. Will try to fix the mentioned issues and test it properly.

Tunous commented 5 years ago

I've fixed the problem with background color. I didn't see that you could customize it separately so now I'm simply moving the background from popup to RecyclerView so everything will look like before and clipping will work.

Unfortunately for KitKat I'm not sure if it's possible to fix clipping issue here. Plus the rounded background for that version looks terrible due to missing shadow. So I've just went ahead and disabled rounded corners sample for per-lollipop versions. I don't have other ideas...

Tunous commented 5 years ago

Oh and here is sample with proper padding now:

zawadz88 commented 5 years ago

For KitKat the solution would be to prepare a custom 9-patch with rounded corners + have the bottom/tip items in the list also use a background with rounded corners. However, I think that might a bit too much for a sample app.