引用:http://uuubd.iteye.com/blog/1485666
listview中的item们默认点击后变成黄颜色,这次我们自定义该样式,将背景色改为绿色
在drawable下新建一个customer.xml
customer.xml
然后再listview的item.xml中设置背景色,android:background
item.xml
在drawable下新建一个customer.xml
customer.xml
- <?xml version="1.0" encoding="utf-8"?>
- <selector
- xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_pressed="true">
- <color android:color="#76EE00"/>
- </item>
- <item android:state_pressed="false">
- <color android:color="#000000"/>
- </item>
- </selector>
然后再listview的item.xml中设置背景色,android:background
item.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:background="@drawable/customer"
- android:orientation="horizontal"
- >
- <ImageView
- android:id="@+id/image"
- android:layout_width="50dp"
- android:layout_height="50dp"
- android:src="@android:drawable/ic_delete"
- android:layout_gravity="center_vertical"
- />
- <TextView
- android:id="@+id/text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textSize="25sp"
- android:text="alsjdalksj"
- android:layout_gravity="center_vertical"
- />
- </LinearLayout>