views:

341

answers:

2

I have a background color applied to a ListView

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

but everytime the list is scrolled the background color changes back to the system default (black). When the scrolling stops the color goes back to @color/window_background.

The style is applied in AndroidManifest.xml:

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

and my ListView looks like this:

<?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>

How can I prevent this from happening?

+1  A: 

You can use the attribute android:colorCacheHint on your ListView to set an RGB value that should be used as the background colour for the list item when it is touched.

For more info see: http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html

Jack Patmos
I'm trying to keep my layout separated from the styling. Is there a way to apply the `colorCacheHint` over the `styles.xml`?
Mannaz
Got it by miself: http://stackoverflow.com/questions/2416276/list-item-background-is-changing-on-scroll/2416388#2416388
Mannaz
A: 

I already figured it out myself

<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>

thanks.

Mannaz