如何改变溢出菜单(弹出式菜单)的背景颜色的操作栏



我正在使用android紧凑库来构建旧版本和新版本的android操作栏。我的需求包括我需要用蓝色显示动作栏。现在我已经改变了操作栏的背景颜色为蓝色,现在我想改变弹出菜单的背景颜色,当我们点击溢出图标。我尝试了很多方法,但都无法改变背景颜色。有没有人建议我们是否可以使用app-compact库更改弹出式菜单的背景颜色,如果我们可以请建议我

添加到您的工具栏元素

app:popupTheme="@style/ThemeOverlay.YourApp"

然后在styles.xml中定义弹出式菜单样式

<style name="ThemeOverlay.YourApp" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:colorBackground">@color/your_background_color</item>
    <item name="android:textColor">@color/your_text_color</item>
</style>

请注意,您需要使用colorBackground而不是background。后者将应用于所有内容(菜单本身和每个菜单项),前者仅应用于弹出式菜单。

来源:Style appcompat-v7工具栏菜单背景

在样式中使用android:popupBackground

<style name ="MyPopupMenu" parent="Theme.AppCompat.Light">
    <item name="popupMenuStyle">@style/MyPopupMenuStyle</item>
</style>
<style name="MyPopupMenuStyle">
    <item name="android:dropDownSelector">@drawable/abc_list_selector_holo_dark</item>
    <item name="android:popupBackground">@drawable/abc_menu_dropdown_panel_holo_dark</item>
    <item name="android:dropDownVerticalOffset">0dip</item>
    <item name="android:dropDownHorizontalOffset">0dip</item>
    <item name="android:dropDownWidth">wrap_content</item>
</style>

最新更新