0

以下のコードを使用して、ListView アイテムのクリックのスタイルを変更します。
list_four_corner_selector.xml

<?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);
}

しかし、アイテムをクリックすると、アイテムの四隅にデフォルトの色が表示されます。
デフォルトを非表示にしたい。
どうすればいいですか?

4

1 に答える 1

2

で使っandroid:listSelectorてみてくださいListView

于 2012-08-24T09:55:07.647 に答える