我想自定义操作栏中溢出菜单的行。我找到了一篇很棒的博客文章,解释了如何进行此操作,这似乎很简单。链接在下面。
http://scriptedpapers.com/2014/08/12/android-action-bar-overflow-menu-customization/
我特别想更改溢出菜单行的背景颜色,因此我正在使用的主题如下所示:
<resources>
<!--the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/CustomActionBar</item>
<item name="android:homeAsUpIndicator">@drawable/upcaret</item>
<item name="android:actionOverflowButtonStyle">@style/CustomOverflowButton</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>
<!--ActionBar style -->
<style name="CustomActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/customBlue</item>
</style>
<style name="CustomOverflowButton" parent="@android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">@drawable/overflowbutton</item>
</style>
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">@color/customBlue</item>
</style>
将此主题应用于应用程序,尽管设置了自定义popupMenuStyle,但溢出菜单的背景颜色仍与Holo.Light.DarkActionBar的默认颜色相同。
在我的项目中,minSdkVersion为15,targetSdkVersion为19。
有人有什么想法吗?
谢谢。
最佳答案
尝试指定9色可绘制对象而不是颜色。
转到here并通过从“弹出式颜色”下拉菜单中选择一种颜色来选择想要的行颜色。
压缩文件中唯一需要的文件是menu_dropdown_panel.9.png
。
确保将此文件放置在您的各个drawable-xxxx
文件夹中。
然后像这样使用它:
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">@drawable/menu_dropdown_panel</item>
</style>
如果仍然无法使用,请将其添加到上面:
将此行添加到您的主主题(CustomActionBarTheme):
<item name="android:actionBarWidgetTheme">@style/PopupWrapper</item>
然后添加:
<style name="PopupWrapper" parent="@android:style/Theme.Holo">
<item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>