我需要設置在列表視圖中的行交替色彩,但是當我做,它消除/禁用上聚焦默認黃色背景具有交替顏色和聚焦色的Android的ListView
我的backgroundColor rowView.setBackgroundColor嘗試(一些顏色);
也與backgrounddrwable。
rowView.setBackgroundColor(R.drawable.view_odd_row_bg);
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_window_focused="false"
android:drawable="@color/odd" />
<!--
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="@color/highlight" />
<item
android:state_focused="true"
android:state_enabled="false"
android:drawable="@color/highlight" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@color/highlight" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@color/highlight" />
<item
android:state_focused="true"
android:drawable="@color/highlight" />
</selector>
,但它不會工作。
有什麼辦法可以同時設置背景顏色和焦點顏色。
我該怎麼做,使用bindView? 我試過這樣的事情: int i = 0; view.setBackgroundResource(i%2 == 0?R.drawable.bindview_bg_gray:R.drawable.bindview_bg_white); i ++; 但經過幾次滾動它變得雜亂無章! – 2010-07-16 04:44:33
非常遲到的評論,但後代:菲利普是依靠bindView的順序調用,你不應該這樣做。永遠不要假設任何關於bindView調用的順序。而是嘗試對cursor.getPosition()(遊標是bindView方法的參數之一)進行模運算。 – benvd 2010-11-22 11:19:06