2010-03-10 14 views
4

我已經申請到ListView列表項的背景正在改變滾動

<style name="CKButtons"> 
    <item name="android:windowBackground">@color/window_background</item> 
</style> 

背景顏色,但每次列表滾動的背景顏色更改回系統默認的(黑色)。滾動停止時,顏色會回到@color/window_background

風格在AndroidManifest.xml應用:

<activity android:name=".event.EventList" 
    android:theme="@style/CKButtons"></activity> 

和我的ListView看起來像這樣:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<ListView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/android:list"/> 
<TextView 
    android:id="@+id/android:empty" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:text="@string/eventlist_no_items"/> 
</LinearLayout> 

我怎樣才能防止這種情況發生?

回答

1

我已經想通了自己

<style name="CKButtons"> 
    <item name="android:windowBackground">@color/window_background</item> 
    <item name="android:listViewStyle">@style/CKListview</item> 
</style> 

<style name="CKListview" parent="android:style/Widget.ListView"> 
    <item name="android:cacheColorHint">@color/window_background</item> 
</style> 

感謝。

2

您可以使用ListView上的屬性android:cacheColorHint來設置RGB值,該值應該用作觸摸時列表項的背景色。

欲瞭解更多信息,請參閱:http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html

+0

我試圖讓我的佈局與樣式分開。有沒有辦法在'styles.xml'上應用colorCacheHint? – Mannaz 2010-03-10 11:15:40

+0

明白了這一點:http://stackoverflow.com/questions/2416276/list-item-background-is-changing-on-scroll/2416388#2416388 – Mannaz 2010-03-10 11:29:20