[英]How to change background color of ListView item?
There is the following method: 有以下方法:
@Override
public void mark() {
ImageView image=(ImageView)view.findViewById(R.id.listItemRepeatingTypeImage);
image.setBackgroundColor(Color.RED);
image.invalidate();
Log.e("event", "mark");
view.setBackgroundColor(Color.GREEN);
view.invalidate();
}
As you can see, I try to change background color for View and ImageView (view is an item of ListView). 如您所见,我尝试更改View和ImageView的背景颜色(view是ListView的一项)。 This event becomes, but there is no new background. 发生了此事件,但是没有新的背景。 How can I fix it? 我该如何解决?
Try to apply this style to your ListView: 尝试将此样式应用于您的ListView:
<style name="List">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:background">#FFFFFF</item>
<item name="android:dividerHeight">1dp</item>
<item name="android:divider">#CCCCCC</item>
<item name="android:cacheColorHint">#FFFFFF</item>
<item name="android:listSelector">#00000000</item>
</style>
And in your xml layout this: 在您的xml布局中:
<ListView
android:id="@+id/listView"
style="@style/List"
android:paddingTop="1dp"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.