问题描述
是有可能改变从白色背景黑色背景默认的黑色文本弹出菜单样式不应用样式的整个活动(打破我的用户界面)?
is it possible to change pop-up menu style from default black text on white background to dark background without applying style to the whole activity (which breaks my UI)?
推荐答案
您不能设置的PopupMenu
直接的风格,但也有其他的方式。
You cannot set PopupMenu
style directly, but there are other ways.
的PopupMenu
创建方式如下:
PopupMenu popupMenu=new PopupMenu(context, anchorView);
菜单的风格是由上下文传递的风格决定的。因此,所有你需要做的是通过你的活动
引用的语境和菜单会相应风格。
The style of menu is determined by the style of context you pass. So all you need to do is to pass your Activity
reference as context, and menu will be styled accordingly.
如果您要定义自己的风格,继承了您的活动风格从默认的值之一,覆盖了以下项目:
If you want to define the style yourself, inherit your activity style from one of the default ones and override the following items:
<style name="style" parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle">...</item>
<item name="android:popupAnimationStyle">...</item>
<item name="android:popupBackground">...</item>
<!-- etc etc -->
</style>
这篇关于如何风格PopupMenu的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!