我想自定義在ListView項目的選擇效果,但我不認識路。如何自定義的ListView Seletion Android中
將是有益的,如果我要更改選擇項目的背景,不同的PNG當用戶選擇該項目。
有什麼建議嗎?
我想自定義在ListView項目的選擇效果,但我不認識路。如何自定義的ListView Seletion Android中
將是有益的,如果我要更改選擇項目的背景,不同的PNG當用戶選擇該項目。
有什麼建議嗎?
使用這個選擇:
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:divider="@null"
android:dividerHeight="0dip"
android:listSelector="@drawable/list_selector" />
選擇:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/yourdrawable" />
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/yourdrawable" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/yourdrawable" />
<item android:drawable="@drawable/yourdrawable" />
</selector>
這是一個good tutorial它。
你所尋找的是選擇 創建資源選擇XML並設置列表項的選擇XML的背景。 例子:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/selected" /> <item android:drawable="@drawable/normal" /> </selector>
也要看: http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
你想在列表視圖圖標?你的問題不清楚。 – NewUser
這聽起來像是一個設計問題。 – mango
沒有我想要的方式來改變Android的列表視圖...默認選擇效果(在默認情況下,Android的列表視圖,當你點擊一個項目這成了像藍) – AndreaF