How to change the background color of Action Bar's Option Menu in Android 4.2?

后端 未结 17 1076
别那么骄傲
别那么骄傲 2020-11-22 16:00

I\'d like to change the background color of the option (overflow) menu in Android 4.2. I have tried all the methods but it is still showing the default color set by the them

相关标签:
17条回答
  • 2020-11-22 17:00

    FAST way!

    styles.xml
    
    <style name="popupTheme" parent="Theme.AppCompat.Light">
    
        <item name="android:background">@color/colorBackground</item>
        <item name="android:textColor">@color/colorItem</item>
    
    </style>
    

    Then add this specific styles to your AppTheme styles

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        ...
        <item name="popupTheme">@style/popupTheme</item>
    </style>
    

    DONE!

    0 讨论(0)
  • 2020-11-22 17:00

    Add following to your Styles.xml

    <style name="Custom_Theme" parent="Theme.AppCompat.Light.DarkActionBar">
    
        <item name="android:itemBackground">@color/white</item>
        <item name="android:textColor">@color/colorPrimaryDark</item>
    
    </style>
    

    Change theme in activity_main.xml only.

    android:theme="@style/Custom_Theme"
    
    0 讨论(0)
  • 2020-11-22 17:02

    To alter the color of the app bar only, you just have to change the colorPrimary value inside the colors.xml file and the colorPrimaryDark if you want to change the battery bar color as well:

    <resources>
      <color name="colorPrimary">#B90C0C</color>
      <color name="colorPrimaryDark">#B90C0C</color>
      <color name="colorAccent">#D81B60</color>
    </resources>
    
    0 讨论(0)
  • 2020-11-22 17:04

    I'm also struck with this same problem, finally i got simple solution. just added one line to action bar style.

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
        <item name="android:textColorPrimary">@color/colorAccent</item>
        <item name="android:colorBackground">@color/colorAppWhite</item>
    </style>
    

    "android:colorBackground" is enough to change option menu background

    0 讨论(0)
  • 2020-11-22 17:06

    In case you are working in the latest toolbar in android studio then here is the smallest solution To change the toolbar options menu color, add this to your toolbar element

     app:popupTheme="@style/MyDarkToolbarStyle"
    

    Then in your styles.xml define the popup menu style

    <style name="MyDarkToolbarStyle" parent="ThemeOverlay.AppCompat.Light"> <item name="android:colorBackground">@color/mtrl_white_100</item> <item name="android:textColor">@color/mtrl_light_blue_900</item> </style>

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

    0 讨论(0)
提交回复
热议问题