java 如何设置Android PopupMenu的背景为白色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16878662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set the background of Android PopupMenu to White
提问by joe7wu
I'm struggling with setting the background of PopupMenu. After googling it for a while, I found it should goes to the app theme. To be more specific, this should be defined in the style.xml.
我正在努力设置 PopupMenu 的背景。谷歌搜索一段时间后,我发现它应该转到应用程序主题。更具体地说,这应该在 style.xml 中定义。
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:popupMenuStyle">MY_STYLE</item>
</style>
However, I didn't really figure out which style exactly I should use, as I assume there's a built-in one. I tried with @android:style/Widget.Holo.PopupMenu
and @android:style/Widget.Holo.Light.PopupMenu
, but with no luck.
但是,我并没有真正弄清楚我应该使用哪种样式,因为我假设有一个内置的样式。我试过@android:style/Widget.Holo.PopupMenu
and @android:style/Widget.Holo.Light.PopupMenu
,但没有运气。
采纳答案by daniel_c05
For instance, try something like this:
例如,尝试这样的事情:
<style name="Theme.MyAppTheme" parent="@style/Theme.Holo.Light">
<item name="popupMenuStyle">@style/PopupMenu.MyAppTheme</item>
</style>
And then on the style itself:
然后是风格本身:
<style name="PopupMenu.MyAppTheme" parent="@style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">@drawable/popup_menu_bg_color</item>
</style>
That is the way it's done via ActionBarStyleGeneratorand some old references here on the Developer Site.
这是通过ActionBarStyleGenerator和Developer Site上的一些旧参考完成的方式。