0

I am using android compact library for building the action bar for both older and newer versions of android. so my requirement includes that i need to show action bar in blue color. now i have changed the action bar background color to blue , now i want to change the background color of popup menu which comes when we click on overflow icon. I tried in many ways but nothing is changing the background color.any one suggest me whether we can change the background color of popup menu using app-compact library or not, if we can please suggest me

sindhu
  • 3
  • 1
AndroidDev
  • 1,191
  • 3
  • 16
  • 35

2 Answers2

5

Add this to your toolbar element

app:popupTheme="@style/ThemeOverlay.YourApp"

Then in your styles.xml define the popup menu style

<style name="ThemeOverlay.YourApp" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:colorBackground">@color/your_background_color</item>
    <item name="android:textColor">@color/your_text_color</item>
</style>

Note that you need to use colorBackground and never background. The latter would be applied to everything (the menu itself and each menu item), the former applies only to the popup menu.

Source: Style appcompat-v7 Toolbar menu background

Community
  • 1
  • 1
stackex
  • 3,205
  • 1
  • 11
  • 16
  • If you want to just change the color of the overflow menu, than set android:colorBackground to whatever you want, like @stackex suggested. Thanks a lot. – Zsolt Boldizsar Apr 08 '15 at 06:20
1

Use android:popupBackground into styles.

like

<style name ="MyPopupMenu" parent="Theme.AppCompat.Light">
    <item name="popupMenuStyle">@style/MyPopupMenuStyle</item>
</style>

<style name="MyPopupMenuStyle">
    <item name="android:dropDownSelector">@drawable/abc_list_selector_holo_dark</item>
    <item name="android:popupBackground">@drawable/abc_menu_dropdown_panel_holo_dark</item>
    <item name="android:dropDownVerticalOffset">0dip</item>
    <item name="android:dropDownHorizontalOffset">0dip</item>
    <item name="android:dropDownWidth">wrap_content</item>
</style>
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
  • No pankaj its not working. here i should use only "@style/Theme.AppCompat.Light" theme. because i am using appcompact library for supporting both lower and higher versions. so using that theme i have to customize – AndroidDev May 26 '14 at 06:44
  • Then change `android:Theme.Holo.Light` with `Theme.AppCompat.Light` – Pankaj Kumar May 26 '14 at 06:47
  • Thanks for the help. but sorry it is changing the background of Drop down i mean action bar spinner. I need to change the background of menu which comes when we click on over flow menu icon. – AndroidDev May 26 '14 at 07:26
  • https://stackoverflow.com/a/64390171/1638277 for appcompat / material theme v21+ solution – avianey Oct 16 '20 at 13:35
  • @avianey your solution does not work. – Xam Apr 15 '22 at 18:06