listview中item改变默认点击样式

引用:http://uuubd.iteye.com/blog/1485666

listview中的item们默认点击后变成黄颜色,这次我们自定义该样式,将背景色改为绿色 
在drawable下新建一个customer.xml 

customer.xml 
Java代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <selector   
  3.     xmlns:android="http://schemas.android.com/apk/res/android">  
  4.     <item android:state_pressed="true">  
  5.         <color android:color="#76EE00"/>  
  6.     </item>  
  7.     <item android:state_pressed="false">  
  8.         <color android:color="#000000"/>  
  9.     </item>  
  10. </selector>  


然后再listview的item.xml中设置背景色,android:background 
item.xml 
Java代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="wrap_content"  
  5.     android:background="@drawable/customer"  
  6.     android:orientation="horizontal"   
  7.     >  
  8.     <ImageView   
  9.         android:id="@+id/image"  
  10.         android:layout_width="50dp"  
  11.         android:layout_height="50dp"  
  12.         android:src="@android:drawable/ic_delete"  
  13.         android:layout_gravity="center_vertical"  
  14.         />  
  15.     <TextView   
  16.         android:id="@+id/text"  
  17.         android:layout_width="match_parent"  
  18.         android:layout_height="wrap_content"  
  19.         android:textSize="25sp"  
  20.         android:text="alsjdalksj"  
  21.         android:layout_gravity="center_vertical"  
  22.         />  
  23.       
  24. </LinearLayout>  
 
原文地址:https://www.cnblogs.com/sode/p/2717709.html