其實這個問題一直困擾著我,後來終於解決了。其實很簡單看下面的,不好意思,有點模糊:
1、listView控制項
<ListView
android:id="@+id/contact_listview"
android:layout_width="wrap_content"
android:layout_height="400dip"
android:divider="#b9b9b9"
android:dividerHeight="1px"
android:cacheColorHint="#00000000"
android:listSelector="@drawable/list_selector"
android:headerDividersEnabled="true">
</ListView>
如果是繼承ListActivity的話,則可以這樣設定。
this.getListView().setSelector(getResources().getDrawable(R.drawable.list_selector));
2、在drawable檔案夾中見一個list_selector.xml檔案,如果什麼內容都不定,只是用來把系統內建的給覆蓋掉,在這裡我們添加上我要添加的小圖片,其中list_item_color.png只是一張只有10*10透明的圖片,list_item_sel_color也是一 張10*10的淺藍色的圖片。
list_item_sel_color:
list_item_color:
<?xml version="1.0" encoding="UTF-8"?><br /><selector xmlns:android="http://schemas.android.com/apk/res/android"><br />Non focused states<br /><item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/list_item_color" /><br /> <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/list_item_sel_color" /><br /> Focused states<br /> <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/list_item_sel_color" /><br /> <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/list_item_sel_color" /><br /> Pressed <item android:state_pressed="true" android:drawable="@drawable/list_item_sel_color" /></p><p></selector>
以上就可以完成背景的設定 效果如下: