简体   繁体   English

更改 Honeycomb 上已激活列表项背景的颜色

[英]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.对于 Honeycomb,我已将我的列表视图项设置为使用?android:attr/activatedBackgroundIndicator样式,因此它们在选择时保持突出显示。

How do I change the colour of the highlight?如何更改突出显示的颜色?

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" . 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它有一个响应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.主题步骤是可选的,(如果您选择,您可以直接使用 state 列表可绘制,)但它提供了额外的一层灵活性,并且由于您已经定义了 ListView 项目以使用该主题属性,您可以在一个中进行此更改影响任何使用自定义主题的活动的地方。

If you need more info on themes look here: http://developer.android.com/guide/topics/ui/themes.html如果您需要有关主题的更多信息,请查看此处: http://developer.android.com/guide/topics/ui/themes.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果未选中列表视图中的项目,如何在列表视图中更改背景颜色 - How to change background colour in List view if the item in list view is unselected 在列表中选中项目时更改图像。 Android蜂窝 - Change an image when item checked in the list. Android Honeycomb 在列表视图中更改所选项目或行的背景颜色 - Change background colour of selected item or row in listview 更改listview中第一个项目的背景颜色 - Change background colour for first item in listview ListFragment激活的项目背景 - ListFragment activated item background 我的列表(Recyclerview)显示在多个屏幕上想要仅在一个屏幕上更改列表项的背景颜色 - my list (Recyclerview) displays on multiple screens want to change the background colour of list item on only one screen 将特定项目的背景更改为颜色,将其他项目更改为不同的颜色 - Change background of particular item to a colour and other items to different colour 激活/选择ListView中的项目时更改视图背景 - Change the view background when an item from a ListView is activated/selected GridView setOnItemClickListener 更改项目背景颜色,删除所有其他项目的背景颜色 - GridView setOnItemClickListener change item background colour, remove background colour of all other item 更改基于SimpleCursorAdapter字段的Lis​​tView项目的背景颜色? - Change background colour of ListView item based on SimpleCursorAdapter field?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM