Search code examples
androidcolorspreference

Scrolling a preference changes everything to white


I have a preference screen like this:

 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
 >

    <CheckBoxPreference
        android:title = "Turn parrot on" 
        android:defaultValue="false"
        android:enabled="true"

        android:persistent="true"

        android:key="turning parrot" />
     <ListPreference
         android:key = "interval"
         android:title = "Talking interval"
         android:persistent="true"
         android:enabled="true"
         android:entries="@array/updateInterval"
         android:entryValues="@array/updateIntervalValues"
         android:dependency="turning parrot"
         android:defaultValue = "1"
         />

     <ListPreference
         android:key = "language"

         android:title = "Talking language"
         android:persistent="true"
         android:enabled="true"
         android:entries="@array/talkinglanguages"
         android:entryValues="@array/talkinglanguagesValues"
         android:dependency="turning parrot"
         android:defaultValue = "1"
         />

 </PreferenceScreen>

When I scroll the preference list, everything changes to white. If my list is a list view I should have done the following

listView = (ListView) this.findViewById(R.id.listview); 
listView.setCacheColorHint(Color.TRANSPARENT);

I learnt that from here

But my preference list does not have an id. How can I change the cache color to get rid of the white when scrolling.


Solution

  • Preference screen is made of a standard ListView and has a default Android id list.

    ListView listView = (ListView)findViewById(android.R.id.list);
    

    Use that to set a cache color hint.