23

I am trying to change the color of the rollover effect when you touch an ActionBar Item. On my Galaxy Nexus with 4.0.2 it's kind of a turquoise color shading which I want to be in a different color.

To be clear, I am talking about ActionBar items here, not navigation tabs.

I got it working under the compatibility library, but for Android 3.0 and higher, i.e. the "real" ActionBar, I just can't figure out how to do this.

Does anyone knows if and how this can be achieved?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Micky
  • 5,578
  • 7
  • 31
  • 55

1 Answers1

46

The native action bar uses the theme attribute selectableItemBackground for action item background drawing. This should be a state-list drawable.

Here's the declaration in Theme.Holo:

<style name="Theme.Holo">
    <!-- bunch of things -->
    <item name="android:selectableItemBackground">@android:drawable/item_background_holo_dark</item>
    <!-- bunch of things -->
</style>

And its drawable XML:

<selector xmlns:android="http://schemas.android.com/apk/res/android"
          android:exitFadeDuration="@android:integer/config_mediumAnimTime">

    <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
    <item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_disabled_holo_dark" />
    <item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/list_selector_disabled_holo_dark" />
    <item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition_holo_dark" />
    <item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition_holo_dark" />
    <item android:state_focused="true"                                                             android:drawable="@drawable/list_focused_holo" />
    <item                                                                                          android:drawable="@color/transparent" />
</selector>
Ahmad
  • 69,608
  • 17
  • 111
  • 137
Jake Wharton
  • 75,598
  • 23
  • 223
  • 230
  • Thanks for your quick response. But if I try to overwrite this attribute in the style with something like I get an error: No resource found that matches the given name: attr 'selectableItemBackground'. How or where can I override this attribute? – Micky Jan 26 '12 at 14:49
  • Sorry, you'll have to use `name="android:selectableItemBackground"`. It's not specified in the Android platform version of the theme because its default package is already 'android'. I updated the answer. – Jake Wharton Jan 26 '12 at 15:54