2012-08-24 96 views
0

我用下面的代碼來修改ListView項點擊的風格單擊樣式。
list_four_corner_selector.xml如何修改ListView控件

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:state_pressed="true" 
     android:drawable="@drawable/list_four_corner_selected" 
    /> 
    <item 
     android:drawable="@drawable/list_four_corner_unselect" 
    /> 
</selector> 

list_four_corner_unselect.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient android:startColor="#FFFFFF" 
     android:endColor="#FFFFFF" 
     android:angle="270"/> 
    <corners android:bottomLeftRadius="10dip" 
     android:bottomRightRadius="10dip" 
     android:topRightRadius="10dip" 
     android:topLeftRadius="10dip" /> 
    <stroke 
     android:width="1dp" 
     android:color="#dddddd" 
     android:dashWidth="10dp" 
     android:dashGap="0dp" /> 
</shape> 

list_four_corner_selected.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient android:startColor="#B7D5F9" 
     android:endColor="#B7D5F9" 
     android:angle="270"/> 
    <corners android:bottomLeftRadius="10dip" 
     android:bottomRightRadius="10dip" 
     android:topLeftRadius="10dip" 
     android:topRightRadius="10dip" /> 
</shape> 

而下面的代碼在BaseAdapter:

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    ViewTag viewTag; 
    if(convertView == null) { 
     convertView = myInflater.inflate(R.layout.row_item, null); 
     viewTag = new ViewTag((TextView)convertView.findViewById(R.id.row_title)); 
     convertView.setTag(viewTag); 
    } 
    else { 
     viewTag = (ViewTag)convertView.getTag(); 
    } 
    convertView.setBackgroundResource(R.drawable.list_four_corner_selector); 
} 

但是當我點擊項目,該項目的四個角會顯示默認的顏色。
我想讓默認隱藏。
我該怎麼做?

回答