0

I'd like to create a custom PopupMenu (be able to change text color, background and icon). Ideal behavior would be like on this gfy (taken from Solid Explorer):

https://gfycat.com/JealousMeanHorsefly

enter image description here

Do you think it's a PopupMenu or ListPopupWindow? I was trying to style PopupMenu like here, but I've only managed to change background color (oh and shadow disappeared). Any ideas how to create such a beautiful dialog?

Edric
  • 24,639
  • 13
  • 81
  • 91
rafakob
  • 3,946
  • 3
  • 26
  • 36

3 Answers3

2

I think the best way is to implement it by creating a custom dialog then set its content view.

          Dialog d = new Dialog(hostActivity,R.style.customOne);
          d.setContentView(yourPopupView);
          d.show();

and u need to change the style of the dialog as below

     <style name="customOne" parent="@android:style/Theme.Dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowSoftInputMode">adjustResize</item>
    <item name="android:windowCloseOnTouchOutside">false</item>
    </style>

hope this will help.

M.Khouli
  • 3,992
  • 1
  • 23
  • 26
0

Check out this library: https://github.com/shehabic/Droppy

It allows you to create custom popups/drop-down menus.

Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73
0
<item name="android:popupMenuStyle">@style/MyPopupMenu</item>
<item name="textAppearanceLargePopupMenu">@style/popupText</item>
<item name="textAppearanceSmallPopupMenu">@style/popupTextSmall</item>

Add the above fields in your base theme.You can further customise your text in the below styles.

<style name="popupText" parent="TextAppearance.AppCompat.Light.Widget.PopupMenu.Large">
    <item name="android:textColor">@color/White</item>
</style>

<style name="MyPopupMenu" parent="Widget.AppCompat.PopupMenu">
    <item name="android:popupBackground">@color/popupbackgroundColor</item>
</style>
<style name="popupTextSmall" parent="TextAppearance.AppCompat.Light.Widget.PopupMenu.Small">
    <item name="android:textColor">@color/White</item>
</style>

Also refer to this answer to show images in popup

You can also set PopupTheme in toolbar.

Community
  • 1
  • 1
Ravi Theja
  • 3,371
  • 1
  • 22
  • 34
  • There're couple of problems: 1) When I set ```@style/MyPopupMenu``` background color isn't changing. 2) ```When I set @style/MyPopupMenu``` background color does chaging, but the popup shadow disappeares. – rafakob Feb 25 '16 at 15:47