Android – How to change the background color of dropdown menu in the actionbar

androidandroid-actionbarandroid-menubackground-colordrop-down-menu

I'm working on an android app and I'm facing some problems in designing my actionbar. I'm using the dark actionbar with white icons on it. I have a dropdown menu popped when I click the overflow icon. Everything is good but I need light background for the dropdown menu with red colored text. I have tried editing the theme in styles.xml but I can only change the background color of dropdown menu when I'm using the light colored theme.

I can get the light colored dropdown menu when I change the Theme.Base.AppCompat.Light.DarkActionBar to Theme.Base.AppCompat.Light but other icons like 'Search' turn very light and hardly visible (see 2nd picture). How can I change the text color on the drop down menu from black to red and make the 'Search' icon visible.

enter image description here enter image description here

Here is the code for more insight

styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.Base.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:popupMenuStyle">@style/MyPopUpMenu</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@color/gloryred</item>
</style>

<style name="MyPopUpMenu"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:popupMenuStyle">@color/white</item>
</style>

menu_actions.xml

<?xml version="1.0" encoding="utf-8"?>

<item android:id="@+id/action_search"
    android:title="@string/action_search"
    android:icon="@drawable/ic_action_search"
    com.example.unitedstates.app:showAsAction="ifRoom"
    com.example.unitedstates.app:actionViewClass="android.widget.SearchView"/>

<item android:id="@+id/action_overflow"
    android:title="@string/action_overflow"
    android:icon="@drawable/ic_action_overflow"
    com.example.unitedstates.app:showAsAction="ifRoom">
    <menu>
        <item
            android:id="@+id/action_help"
            android:title="@string/action_help"
            android:icon="@drawable/ic_action_help"
            android:showAsAction="never"/>
        <item
            android:id="@+id/action_about"
            android:title="@string/action_about"
            android:icon="@drawable/ic_action_about"
            android:showAsAction="never"/>
        <item
            android:id="@+id/action_feedback"
            android:title="@string/action_feedback"
            android:icon="@drawable/ic_action_feedback"
            android:showAsAction="never"/>
    </menu>
</item>

Best Answer

You can change the background color and text color of the dropdown menu in the actionbar like this.

Set the style for the popup menu in styles.xml.

 <style name="PopupMenuStyle" parent="Theme.AppCompat.Light">

         <item name="android:background">@color/YourColor</item>
         <item name="android:textColor">@Color/YourColor</item>

</style>

Now set this style as the popupTheme for your toolbar.

<android.support.v7.widget.Toolbar  
      xmlns:app="http://schemas.android.com/apk/res-auto"          
      xmlns:android="http://schemas.android.com/apk/res/android"

          // rest of your code
      app:popupTheme="@style/PopupMenuStyle" />