1

I am using ListView inside a ViewFlipper as follows:

<ViewFlipper
    android:id="@+Category/viewFlipper"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
   <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:entries="@array/options"
        android:cacheColorHint="#FFFFFF"
        android:background="#FFFFFF"/>
</ViewFlipper>

I want to change the background color of the ListView. I have only 5 items in the options array and they do not fill the screen. So, the remaining part of the listView appears in the default grey color. I want to change this default color. I read about cacheColorHint attribute in questions posted by others related to this. But it did not work out. Can anyone please help me with this?

Thanks in advance

andro
  • 977
  • 1
  • 10
  • 21

2 Answers2

0

Set a selector as the background of your ListView:

ListView mylw = findViewById(R.id.mylistView);
//Do not use reserved  android or java identifiers as your id or variable!
mylw.setBackgroundResource(R.drawable.thexmlbelow);

Drawable:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false" android:drawable="Background Color" />
    <item android:drawable="Background Color when pressed" />
</selector>
Brais Gabin
  • 5,827
  • 6
  • 57
  • 92
Ahmad
  • 69,608
  • 17
  • 111
  • 137
0

You should use layout_height="wrap_content" (and layout_width="wrap_content" also if need) for your ListView and change the "default grey color" like you said by set the background for ViewFlipper.

Wayne
  • 6,361
  • 10
  • 46
  • 69