zawadz88 / MaterialPopupMenu

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

Allow customizing default popup style via theme attribute #53

Closed Tunous closed 5 years ago

Tunous commented 5 years ago

This pull request adds materialPopupStyle attribute which allows customizing the default style that will be used by all of the popups created by this library (unless overridden in the builder via style property)

Example

2019-04-16_18-37-44

Here I've applied the below change. Notice how all of the popups except for these that define custom style have changed to that dark style with dimmed background.

diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml
index a7db238572786f68142759156494a2229cc7e331..85c90ef297367cb01a3d015365322964d579e1eb 100644
--- a/sample/src/main/res/values/styles.xml
+++ b/sample/src/main/res/values/styles.xml
@@ -13,6 +13,7 @@
         <item name="colorPrimary">@color/lightColorPrimary</item>
         <item name="colorPrimaryDark">@color/lightColorPrimaryDark</item>
         <item name="colorAccent">@color/colorAccent</item>
+        <item name="materialPopupMenuStyle">@style/Widget.MPM.Menu.Dark.Dimmed</item>
     </style>

     <style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">

Additional change

I've also cleaned a bit usage of ContextThemeWrapper. Now it's created only once and passed to MaterialRecyclerViewPopupWindow directly as a Context. Also I've removed the context from PopupMenuAdapter and instead made all views inherit from their parent view context which in turn makes them use the context from MaterialRecyclerViewPopupWindow. (Unless I'm somehow mistaken 😏). You can ignore that second commit if you don't want that change. It shouldn't affect the topic of this pull request but I found it related enough to keep here.