0

I've got two shapes like this:

List_selector_focused.xml

<gradient
    android:startColor="#f5c98c"
    android:endColor="#f7ddb8"
    android:angle="90" />

</shape>

and list_selector_pressed.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
   android:shape="rectangle">

<gradient
    android:startColor="#fb9d23"
    android:endColor="#ffc579"
    android:angle="90" />

</shape>

and my list_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_selector_pressed" />

<item
    android:state_focused="true"
    android:drawable="@drawable/list_selector_focused" />

<item
    android:drawable="@android:color/transparent" />

</selector>

And to my listview, I add the list_selector.xml

 <ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:cacheColorHint="#0A3A5C"
    android:scrollbars="none"
    android:listSelector="@drawable/list_selector">

But there is no color appearing when i press one of the items in the listview, any suggestions?

EDIT

The list I try to apply this to, is a custom list. The layout for each of the items in the list:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingBottom="10dip"
android:paddingLeft="10dip"
android:paddingTop="10dip" >

<TextView
    android:id="@+id/idNumber"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="First"
    android:textColor="#11629F"
    android:textSize="17sp"
    android:textStyle="bold" />

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

</LinearLayout>

<TextView
    android:id="@+id/date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/idNumber"
    android:layout_below="@+id/idNumber"
    android:text="Second"
    android:textSize="15sp" />
 </RelativeLayout>
4

1 回答 1

2

您的项目是否具有恒定的背景颜色?如果是这样,则不会显示您的选择器,因为此选择器设置在项目的背面。确保您的项目的背景在选择时是透明的,以使您的选择器可见。

于 2012-07-24T08:01:57.947 回答