Method One, Drawable/listitem_bk.xmlxml code
- <? XML version= "1.0" encoding="Utf-8" ?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <!--background picture without focus--
- <item android:state_window_focused="false"
- android:drawable="@drawable/pic1" />
- <!--get focus in non-touch mode and click on the background picture--
- <item android:state_focused="true" android:state_pressed="true"
- android:drawable= "@drawable/pic2" />
- <!--the background picture when clicked in touch mode--
- <item android:state_focused="false" android:state_pressed="true"
- android:drawable="@drawable/pic3" />
- <!--picture background When selected--
- <item android:state_selected="true"
- android:drawable="@drawable/pic4" />
- <!--get focus when the picture background--
- <item android:state_focused="true"
- android:drawable="@drawable/pic5" />
- </selector>
In the ListView XML file, add the
android:listselector= "@drawable/listitem_bkOr add attributes to the parent view in XML
android:background= "@drawable/listitem_bk"Method Two, Java code
- drawable drawable = Getresources (). getdrawable (R.drawable.picname);
- Listview.setselector (drawable);
Custom is similar to the item background in a ListView