Define a selector
with its pressed
and default
states in res/drawable
folder(one of the state will be your @drawable/item
). Set it as the bg of your list row layout.
See similar question and answer :Selector on background color of TextView
Edit:
Best way to understand and apply something like google did is, to look into SDK and do similar things to that. For instance look at the btn_default_holo_dark
drawable. It is a selector with states and yes it is a xml.
This is a selector taken from sdk (sdk\platforms\android-18\data\res\drawable\btn_default_holo_dark.xml
)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/btn_default_normal_holo_dark" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="@drawable/btn_default_disabled_holo_dark" />
<item android:state_pressed="true"
android:drawable="@drawable/btn_default_pressed_holo_dark" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/btn_default_focused_holo_dark" />
<item android:state_enabled="true"
android:drawable="@drawable/btn_default_normal_holo_dark" />
<item android:state_focused="true"
android:drawable="@drawable/btn_default_disabled_focused_holo_dark" />
<item
android:drawable="@drawable/btn_default_disabled_holo_dark" />
</selector>
These are the images taken from sdk (sdk\platforms\android-18\data\res\drawable-xhdpi
):
When you apply this drawable/selector (@drawable/btn_default_holo_dark
) to any view, you are going to have its states. I hope this sample makes my answer more clear.