state_activated and ListView item选中效果

来源:互联网 发布:java短信验证码接口 编辑:程序博客网 时间:2024/05/17 07:56

首先编写selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_focused="true"    android:state_pressed="true" android:drawable="@color/headers_layout_bg_color" />    <item android:state_focused="false"   android:state_pressed="true" android:drawable="@color/headers_layout_bg_color" />    <item android:state_activated="true" android:drawable="@drawable/list_section_divider_holo_light" />    <item android:drawable="@color/transparent" /></selector>

接着在item layout中设置背景:

android:background=


最后定义ListView的选择模式:

listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);