2

You can change the background of a menu item on the actionbar using the android:actionBarItemBackground attribute.

However, this results in the background of menu items in ActionMode having the same color. Is there a way to have different backgrounds for menu items for the normal ActionBar and the ActionMode?

<item name="android:actionBarItemBackground">@drawable/selectable_background_mytheme</item>

selectable_background_mytheme:

<selector xmlns:android="http://schemas.android.com/apk/res/android"
        android:exitFadeDuration="@android:integer/config_mediumAnimTime" >
    <item android:state_pressed="false" android:state_focused="true" android:drawable="@color/red" />
    <item android:state_pressed="true" android:drawable="@color/blue" />
    <item android:drawable="@android:color/transparent" />
</selector>
nhaarman
  • 98,571
  • 55
  • 246
  • 278

1 Answers1

0

You should use android:actionLayout, see here: Android action bar menu item with actionLayout not working properly

Some other notes:

Your file "selectable_background_mytheme" should look something like this:

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetBottom="0dp"
    android:insetLeft="-5dp"
    android:insetRight="-5dp"
    android:insetTop="-5dp" >

    <shape>
        <solid android:color="@color/stacked_green" />

        <stroke
            android:width="3dp"
            android:color="@color/accent_green" />
    </shape>
</inset>

i.e. not a selector

Alternatively you could use a bitmap drawable.

Community
  • 1
  • 1
intrepidis
  • 2,870
  • 1
  • 34
  • 36