Hello Friends,
This is very common issue I saw in android with Listview. In one of my app I am using a
listview for displaying the list of Items.I set the background of Listview as blue. Below is
the Listview code which I am using.
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:background="#0000FF"/>
But, some times when I scroll the Listview the background color will be automatically change
to black or white. Then, I found a solution I added below line in my Listview(in xml file).
android:cacheColorHint="#00000000"
OR
android:cacheColorHint="@android:color/transparent"
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:cacheColorHint="#00000000"
android:choiceMode="singleChoice"
android:background="#2A323D"/>
OR at java code,use below line of code
listview.setCacheColorHint(Color.TRANSPARENT);
After adding the above one line in my xml or java file , the Listview background color
change on scrolling issue will be gone.
Hope , the above code helps some one.
Enjoy coding......
This is very common issue I saw in android with Listview. In one of my app I am using a
listview for displaying the list of Items.I set the background of Listview as blue. Below is
the Listview code which I am using.
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:background="#0000FF"/>
But, some times when I scroll the Listview the background color will be automatically change
to black or white. Then, I found a solution I added below line in my Listview(in xml file).
android:cacheColorHint="#00000000"
OR
android:cacheColorHint="@android:color/transparent"
And Finally my Listview code contains following code.....
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:cacheColorHint="#00000000"
android:choiceMode="singleChoice"
android:background="#2A323D"/>
OR at java code,use below line of code
listview.setCacheColorHint(Color.TRANSPARENT);
After adding the above one line in my xml or java file , the Listview background color
change on scrolling issue will be gone.
Hope , the above code helps some one.
Enjoy coding......