Search code examples
androidxmlcolorsandroid-actionbarandroid-actionbar-compat

Android menu background black with Theme.AppCompat?


For some reason in my application, when using "Theme.AppCompat" as my style, it makes my Menus black text (which I set since I want black text) on a dark grey background, as shown here:

screenshot

I have tried manually setting the menu's background color using a few online resources but none seem to be working. Does anyone know what might be causing the issue? Below is my style.xml, and as you can see, the two bottom elements in the main app theme entry are me trying to change the background color using things I've found online.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
    <item name="windowActionBar">false</item>
    <item name="android:windowBackground">@color/white_primary</item>
    <item name="android:textColor">@color/text_primary</item>
    <item name="android:textSize">@dimen/text_size_medium</item>
    <item name="colorAccent">@color/black_primary</item>
    <item name="android:popupMenuStyle">@style/PopupMenuStyle</item>
    <item name="android:panelFullBackground">@drawable/menu_full_bg</item>
</style>

<style name="PopupMenuStyle" parent="Theme.AppCompat.Light">
    <item name="android:popupBackground">@android:color/white</item>
</style>

<drawable name="menu_full_bg">#FFFFFF</drawable>


Solution

  • You can change the background color of the popup menu as below.

    1. Create a style in your styles.xml

      <style name="PopupMenuStyle" parent="Theme.AppCompat.Light">
           <item name="android:background">@android:color/white</item>
      </style>
      
    2. Set this theme as your toolbar popup theme in your toolbar.xml

       <android.support.v7.widget.Toolbar     
          xmlns:app="http://schemas.android.com/apk/res-auto"    
          xmlns:android="http://schemas.android.com/apk/res/android"
      
              // Your code here
             app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
             app:popupTheme="@style/PopupMenuStyle" />
      

    Hope this helps.