How to change background color of overflow menu (popup Menu) for action bar

穿精又带淫゛_ 提交于 2019-12-25 01:48:24

问题


I am using android compact library for building the action bar for both older and newer versions of android. so my requirement includes that i need to show action bar in blue color. now i have changed the action bar background color to blue , now i want to change the background color of popup menu which comes when we click on overflow icon. I tried in many ways but nothing is changing the background color.any one suggest me whether we can change the background color of popup menu using app-compact library or not, if we can please suggest me


回答1:


Add this to your toolbar element

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

Then in your styles.xml define the popup menu style

<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>

Note that you need to use colorBackground and never background. The latter would be applied to everything (the menu itself and each menu item), the former applies only to the popup menu.

Source: Style appcompat-v7 Toolbar menu background




回答2:


Use android:popupBackground into styles.

like

<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>


来源:https://stackoverflow.com/questions/23864142/how-to-change-background-color-of-overflow-menu-popup-menu-for-action-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!