Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the touch effect color of the ActionBar in Android 3.0 and higher

Tags:

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?

like image 423
Micky Avatar asked Jan 26 '12 14:01

Micky


People also ask

How to change a action bar style?

To change the action bar background, create a custom theme for your activity that overrides the actionBarStyle property. This property points to another style in which you can override the background property to specify a drawable resource for the action bar background.


1 Answers

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> 
like image 68
Jake Wharton Avatar answered Sep 27 '22 17:09

Jake Wharton