1

For a listview I have a context menu (on items). How can I set (via a style) the background color of the context menu?

From examples I used the following base theme:

<style name="Base.Theme.Xyz" parent="Theme.AppCompat.NoActionBar">
tm1701
  • 7,307
  • 17
  • 79
  • 168

2 Answers2

3

just follow these steps:

If by context menu you mean the menu from the long press, then I have done this with the following code. My menu has my theme's background, and a green highlight.

context menu layout:

<menu
  xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/resetConfirm" android:title="@string/actual_reset"></item>
</menu>

styles.xml, where I'm using a custom theme (which I think is the key)

 <style name="GradientLight" parent="@android:style/Theme.Light">
    <item name="android:windowBackground">@drawable/background</item>
    <item name="android:progressBarStyle">@style/progressBar</item>
    <item name="android:buttonStyle">@style/greenButton</item>
    <item name="android:buttonStyleSmall">@style/greenButton</item>
    <item name="android:listViewStyle">@style/listView</item>
    <item name="android:itemBackground">@drawable/menu_selector</item>
    <item name="android:spinnerStyle">@style/spinner</item>
</style>
<style name="listView" parent="@android:style/Widget.ListView.White">
 <item name="android:background">@drawable/background</item>
 <item name="android:listSelector">@drawable/list_selector_background_green</item>
</style>

From: Override context menu colors in Android

Check this post for one more possible solution.

Hope it help

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
0

Although I am thankful for the previous answer, I found the perfect and very simple solution.

In my project I used this parent:

<style name="Base.Theme.Deholtmans" parent="Theme.AppCompat.NoActionBar">

I got very dark context menu's, etc. Before AppCompat I used the Light version of themes.

The solution is using the right pre-defined parent:

<style name="Base.Theme.Deholtmans" parent="Theme.AppCompat.Light.NoActionBar">

So, the light version. Easy does it!

tm1701
  • 7,307
  • 17
  • 79
  • 168