问题
In my Android app, I am using a popup menu but its background is green.
I want it to be white.
The background is white if I run it on my Android 6.0 device, but shows up green on my Jellybean device.
I'm not using the Actionbar.
There are many posts about this issue and I've tried probably most of them but can't find the solution.
The closest I got was a white background but then the border disappears.
Or I get a white background but when pressing on an item, the selection shows a grey background except for the text's background which shows white.
I'm using AppCompat.
Here are some of the things I've tried:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="colorControlActivated">#d06655</item>
<item name="colorAccent">#ffe6e2</item>
<item name="android:colorActivatedHighlight">#ffe6e2</item>
<item name="android:windowBackground">@color/white</item>
<!--<item name="android:popupMenuStyle">@style/PopupMenu</item>-->
<!--<item name="android:itemBackground">@color/white</item>-->
<item name="popupMenuStyle">@style/myPopupMenuStyle</item>
<item name="android:popupMenuStyle">@style/myPopupMenuStyle</item>
</style>
<!--<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu">-->
<!--<style name="PopupMenu" parent="@style/Widget.AppCompat.PopupMenu">-->
<style name="myPopupMenuStyle" parent="@style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">@android:color/white</item>
</style>
回答1:
You can brash the popup menu by using Android Action Bar Style Generator(or create a 9patch background by your own).
So all I did was - specify proper colour in the generator, get 9patched background(menu_dropdown_panel_background.9.png) back and set it as a background:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="popupMenuStyle">@style/PopupMenu.Example</item>
</style>
<style name="PopupMenu.Example" parent="@style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">@drawable/menu_dropdown_panel_background</item>
</style>
That's it!
来源:https://stackoverflow.com/questions/34206759/changing-the-background-color-of-a-popup-menu