在我的应用程序中,我显示了一个上下文操作栏,因为我没有空间容纳所有操作,所以其中一些操作可以在溢出菜单按钮下访问。现在我想设置溢出菜单的样式并更改其背景。我的主题继承自 Theme.AppCompat,我定义了这些样式:
<item name="android:popupMenuStyle">@style/PopupMenu</item>
<item name="android:listPopupWindowStyle">@style/PopupMenu</item>
<item name="android:dropDownListViewStyle">@style/DropDownListView</item>
<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu">
<!--<item name="android:popupBackground">@color/dark_color</item>-->
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:dropDownSelector">?popupItemBackground</item>
</style>
<style name="DropDownListView" parent="Widget.AppCompat.ListView.DropDown">
<item name="android:listSelector">?popupItemBackground</item>
<item name="android:divider">@null</item>
<item name="android:dividerHeight">0dp</item>
</style>
我的应用程序中的其他菜单(操作栏中的溢出菜单和其他菜单)已设置样式,但上下文操作栏的溢出菜单没有。我应该怎么办?
最佳答案
要更改溢出菜单背景,您需要覆盖属性 actionOverflowMenuStyle
:
<!-- add to your parent style -->
<item name="actionOverflowMenuStyle">@style/LStyled.PopupMenu.OverflowMenu</item>
<style name="LStyled.PopupMenu.OverflowMenu" parent="@style/Widget.AppCompat.PopupMenu.Overflow">
<!-- 'overlapAnchor' changes position of the popup -->
<!-- true - popup will be shown over the overflow button -->
<!-- false - popup will be shown below the overflow button -->
<item name="overlapAnchor">false</item>
<item name="android:popupBackground">@drawable/bg_cab_popup</item>
</style>
Drawable bg_cab_popup
可以是任何类型的 drawable。但是,使用 9 补丁是有意义的。
如果您需要更改背景以外的任何内容,请给我留言。
关于android - CAB溢出菜单自定义样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27524045/