1.通過drawable的selector屬性
chk_payitem_select_status.xml文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_recharge_item_bg" android:state_focused="false" />
<item android:drawable="@drawable/shape_recharge_itemselected_bg" android:state_focused="true" />
</selector>
2.使該item可以獲得焦點(diǎn),和點(diǎn)擊效果
android:clickable="true"
android:focusableInTouchMode="true"
android:focusable="true"
例如:
<RelativeLayout
android:id="@+id/rlItem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/chk_payitem_select_status"
android:clickable="true"
android:focusableInTouchMode="true"
android:focusable="true">
</RelativeLayout>
這樣,當(dāng)點(diǎn)擊某個(gè)條目水醋,該條目背景顏色相應(yīng)改變