3 回答
![?](http://img1.sycdn.imooc.com/533e4c5600017c5b02010200-100-100.jpg)
TA贡献1966条经验 获得超4个赞
是的你可以
<style name="YOURSTYLE" parent="Widget.AppCompat.PopupMenu">
<item name="android:textColor">@android:color/white</item>
<item name="android:itemBackground">@android:color/holo_red_light</item>
</style>
和
Context wrapper = new ContextThemeWrapper(this, R.style.YOURSTYLE);
PopupMenu popup = new PopupMenu(wrapper, view);
![?](http://img1.sycdn.imooc.com/54584ee0000179f302200220-100-100.jpg)
TA贡献1906条经验 获得超10个赞
您不能PopupMenu直接设置样式,但是还有其他方法。
PopupMenu 是通过以下方式创建的:
PopupMenu popupMenu=new PopupMenu(context, anchorView);
菜单的样式由您传递的上下文样式决定。因此,您要做的就是将您的Activity引用作为上下文传递,并且菜单将相应地设置样式。
如果要自己定义样式,请从默认样式之一继承您的活动样式,并覆盖以下各项:
<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>
![?](http://img1.sycdn.imooc.com/533e4d470001a00a02000200-100-100.jpg)
TA贡献1815条经验 获得超6个赞
除了Deville建议的内容外,您还可以在主题样式中添加以下属性。
<style name="style" parent="android:Theme.Holo.Light">
<!-- other attributes -->
<item name="textAppearanceLargePopupMenu">@style/myPopupMenuTextAppearanceLarge</item>
<item name="android:textAppearanceLargePopupMenu">@style/myPopupMenuTextAppearanceLarge</item>
<item name="textAppearanceSmallPopupMenu">@style/myPopupMenuTextAppearanceSmall</item>
<item name="android:textAppearanceSmallPopupMenu">@style/myPopupMenuTextAppearanceSmall</item>
<item name="popupMenuStyle">@style/myPopupMenuStyle</item>
<item name="android:popupMenuStyle">@style/myPopupMenuStyle</item>
</style>
上述样式定义中引用的其他样式
<style name="myPopupMenuStyle" parent="@style/Widget.AppCompat.Light.PopupMenu">
</style>
<style name="myPopupMenuTextAppearanceSmall" parent="@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Small">
<item name="android:textColor">#000000</item>
</style>
<style name="myPopupMenuTextAppearanceLarge" parent="@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Large">
<item name="android:textColor">#000000</item>
</style>
您会在我的xml样式定义中注意到AppCompat,这是因为我正在使用android支持库来定位较低的android API级别。
- 3 回答
- 0 关注
- 1279 浏览
添加回答
举报