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可以获得焦点,和点击效果
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>
这样,当点击某个条目,该条目背景颜色相应改变