Android menu background is black with Theme.AppCompat?

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

screenshot

I tried to manually adjust the background color of the menu using several online resources, but none of them work. Does anyone know what might cause the problem? Below is my style.xml, and, as you can see, the two bottom elements in the main theme of the application theme is an attempt to change the background color using those things that I found on the Internet.

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

+9
source share
6 answers

You can change the background color in the pop-up menu as shown below.

  • Create a style in styles.xml

     <style name="PopupMenuStyle" parent="Theme.AppCompat.Light"> <item name="android:background">@android:color/white</item> </style> 
  • Define this theme as your toolbar popup theme in 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.

+21
source

You can simply use appNS to define popupTheme, as shown below.

 app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
+2
source

To change the color of the toolbar options menu, add this to your toolbar item

 app:popupTheme="@style/MyDarkToolbarStyle" 

Then in your styles.xml define a 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 the background. The latter will apply to everything (the menu itself and each menu item), the first only applies to the pop-up menu.

+1
source

Send link

The accepted answer here worked for me. I just repeat the same answer here again. Add xml to your toolbar

following:
 <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/toolbarbackground" android:elevation="4dp" app:popupTheme="@style/YOUR_THEME_HERE" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" > 

In your styles.xml:

  <style name="YOUR_THEME_HERE" parent="ThemeOverlay.AppCompat.Light"> <item name="android:colorBackground">#000000</item> <item name="android:textColor">#ffffff</item> </style> 

The above style gives a white font on a black background.

Credit at #Eugen Pechanec

0
source

Not sure if this help. This may be a simpler solution. Inside AppCompat - themes_base.xml you will find the section below.

 <!-- Panel attributes --> <item name="panelMenuListWidth">@dimen/abc_panel_menu_list_width</item> <item name="panelMenuListTheme">@style/Theme.AppCompat.CompactMenu</item> <item name="panelBackground">@drawable/abc_menu_hardkey_panel_mtrl_mult</item> <item name="android:panelBackground">@android:color/transparent</item> <item name="listChoiceBackgroundIndicator">@drawable/abc_list_selector_holo_dark</item> 

Create a theme in your application and apply color.

 <style name="Theme.Base" parent="@style/Theme.AppCompat.Light.DarkActionBar"> <item name="android:panelBackground">@android:color/black</item> </style> 
0
source

I obstruct this line:

  <item name="android:background">@android:color/white</item> 

since the pop-up menu animation on my device behaved pretty ugly. Instead, it was simple enough to use this:

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

Source: https://habr.com/ru/post/984275/


All Articles