Use android:state_pressed
to specify pressed states.
Drawable to use: /res/drawable/bg.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/holo_red_dark"/>
</shape>
Selector to use: /res/drawable/item.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/bg"/>
</selector>
ListView:
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:saveEnabled="true"
android:listSelector="@drawable/item"
/>
Result on pressing a list item:
Note: List selector is drawn behind Item View, Item View may have its own background.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…