2

i have made a popup menu. now i want to customize its background color. i have followed some tutorial and stackoverflow but nothing working. app base theme is

Theme.AppCompat.Light.DarkActionBar

my style code is:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <!--<item name="android:popupMenuStyle">@style/OptionMenu</item>-->
    <item name="android:itemBackground">#167be1</item>
</style>

<!--<style name="OptionMenu" parent="@style/Theme.AppCompat.Light.DarkActionBar">-->

    <!--<item name="android:popupBackground">#1278ce</item>-->

<!--</style>-->

can anyone please help me on this issue.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
AAA
  • 485
  • 6
  • 23
  • https://stackoverflow.com/questions/40671629/change-popup-menu-background-color – AskNilesh Mar 29 '18 at 10:32
  • https://www.google.co.in/search?q=custom+popup+menu+background+not+working+site:stackoverflow.com&client=ubuntu&hs=EyC&channel=fs&dcr=0&sa=X&ved=0ahUKEwjSlM2NqpHaAhVLr48KHb8qAIEQrQIIMygEMAA&biw=1600&bih=727 – AskNilesh Mar 29 '18 at 10:32
  • maybe same, infact i have tried with same solution but not working @NileshRathod – AAA Mar 29 '18 at 10:36
  • okay wait, i will let you know if it works or not – AAA Mar 29 '18 at 10:38
  • 1
    thanks its working now :). but why did not work the way i had done with? @NileshRathod – AAA Mar 29 '18 at 10:44
  • yes please. and one more thing how to add margin to menu items? – AAA Mar 29 '18 at 10:58

1 Answers1

2

Try this

<style name="OptionMenu" parent="@style/Theme.AppCompat.Light.DarkActionBar">

    <item name="android:itemBackground">#21B6D7</item>
    <item name="android:textColor">#FFFFFF</item>

</style>

apply theme to your PopupMenu like this

Context contextWrapper = new ContextThemeWrapper(context, R.style.OptionMenu);
PopupMenu popup = new PopupMenu(contextWrapper, v);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163