1、改变listView的选中的颜色 :
listview默认情况下,item的背景色是黑色,在用户点击时是黄色的。如果 需要修改为自定义的背景颜色,一般步骤如下:
1)设置listSelector
2)在布局文件中设置item的background
首先写好selector.xml文件:
<span style="font-size:14px;"><selectorxmlns:android="http://schemas.android.com/apk/res/android">
<itemandroid:drawable="@drawable/bg_light"android:state_pressed="true"/>
</selector></span>
1)设置listview的listSelector:
<span style="font-size:14px;"><ListView
android:id="@+id/bill_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="@android:color/transparent"
android:divider="@android:color/transparent"
android:listSelector="@drawable/selector"//可以少
android:dividerHeight="0px">
</ListView></span>
2)在listitem的布局文件中设置background属性:
<span style="font-size:14px;"><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="66dp"
android:orientation="horizontal"
android:clickable="true"//绝对不能少
android:background="@drawable/selector">//不能少,否则点击没有反应
<TextView
android:id="@+id/detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"/>
</LinearLayout></span>
上述红色加粗部分是绝对不能少的,因为可能会被其他的view点击事件给覆盖掉,这样设置后才能确保修改点击后list的item的颜色为我们自己设置的颜色。