1.在values中添加一个colors的xml文件应于调用。
2.在drawable中添加一个item_selector.xml文件,用于供listview调用。
3.在listview中进行对点击时背景改变时调用。
colors.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent">#00000000</color>// 透明的 当默认的时候也就是不进行点击事件的时候进行调用。
<color name="choose">#9fb01513</color>//当点击时需要显示的颜色。
</resources>
item_selector.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
//默认不被按压的状态
<item android:drawable="@color/transparent" android:state_pressed="false"/>
//按钮被按压下的状态
<item android:drawable="@color/choose" android:state_pressed="true"/>
</selector>
在listview中设置的值:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/lv_show"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<span style="color:#FF0000;">android:listSelector="@drawable/item_selector"</span> //对颜色的改变的调用。
/>
</LinearLayout>