Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change colour of activated list item background on Honeycomb

For Honeycomb, I have set my listview items to use the ?android:attr/activatedBackgroundIndicator style so they remain highlighted when selected.

How do I change the colour of the highlight?

like image 309
Intrications Avatar asked Jul 05 '11 20:07

Intrications


1 Answers

Define a custom theme with the item:

<item name="android:activatedBackgroundIndicator">@drawable/my_background</item>

Next, declare that drawable in a state list .xml file under res/drawable/my_background.xml as illustrated here: http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList Make sure that it has an item that responds to android:state_activated="true". This is your activated highlight.

The theme step is optional, (you could use the state list drawable directly if you choose,) but it gives an added layer of flexibility and since you've already defined your ListView items to use that theme attribute you can make this change in one place to affect any Activity that uses the custom theme.

If you need more info on themes look here: http://developer.android.com/guide/topics/ui/themes.html

like image 124
adamp Avatar answered Oct 20 '22 19:10

adamp