0

How to change color of background in menu? It is white by default. I changed style.xml and menu but it shows white menu yet. what is problem with this code: I can remove

    android:theme="@style/your_custom_optionsMenuStyle"

form manifest.xml and the menu color become black. but i want to know is it good way? and is it be black in other devices with different api?

    <item 
        android:id="@+id/menu_settings"
        android:title="@string/menu_settings"
        android:orderInCategory="100"/>
      <item name="actionOverflowMenuStyle">@style/your_custom_optionsMenuStyle</item>

</menu>

style.xml file: <

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>



<style name="your_custom_optionsMenuStyle" parent="AppBaseTheme">
 <item name="android:popupBackground">#000000</item>
</style>

 </resources>

manifest:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/your_custom_optionsMenuStyle"
      >
user5508330
  • 113
  • 1
  • 1
  • 7
  • Possible duplicate of [How to change ActionBar menu background color (android 4 & 5)](http://stackoverflow.com/questions/28974855/how-to-change-actionbar-menu-background-color-android-4-5) – camelCaseCoder Nov 02 '15 at 07:04

2 Answers2

2

You can override menu style in your app theme from styles xml file using attribute

<item name="actionOverflowMenuStyle">@style/your_custom_optionsMenuStyle</item>

where your_custom_optionsMenuStyle specifies the behaviour of each menu attribute

<style name="your_custom_optionsMenuStyle" parent="Widget.AppCompat.PopupMenu.Overflow">
     <item name="android:popupBackground">your color code</item>
</style>
NIPHIN
  • 1,071
  • 1
  • 8
  • 16
  • so it should change api to 21. is there any way to not change api? – user5508330 Nov 02 '15 at 07:40
  • you can change the widget reference in parent tag to point to corresponding widget that you are using in your current api – NIPHIN Nov 02 '15 at 07:47
  • I change the code and add it to question above. pleas tell me your idea. – user5508330 Nov 02 '15 at 08:46
  • This requires support library install one. If you dont know waht theme you are using or anything like that ask a new question. What I specified is the method to change the style of overflow menu. If you feel this as a correct answer please mark it as one. – NIPHIN Nov 02 '15 at 09:20
  • I don't know it is correct or no. because I get the desired result. – user5508330 Nov 02 '15 at 10:40
0

You need to set style on icons.I prefer to see below link will help How to change the background color of Action Bar's Option Menu in Android 4.2?

Community
  • 1
  • 1
Vasant
  • 3,475
  • 3
  • 19
  • 33