Change colour of activated list item background on Honeycomb

懵懂的女人 提交于 2019-12-18 10:56:18

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/6588750/change-colour-of-activated-list-item-background-on-honeycomb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!