1

`我正在使用列表选择器,但它不能正常工作。单击列表项后我得到效果,但在单击项目之前没有效果。这是我的选择器代码:

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

    <item android:state_pressed="true"
        android:drawable="@drawable/headerplain" />

    <item 
    android:state_focused="true" 
    android:state_pressed="false" 
    android:drawable="@drawable/headerplain" />

    <item android:state_selected="true"
     android:state_pressed="false"
        android:drawable="@drawable/headerplain" />
</selector>

and I have applied it to listView as 
 <ListView
        android:id="@+id/listView123"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"         
        android:listSelector="@drawable/list_selector"
        android:drawSelectorOnTop="true"
        android:focusable="true"
        >
    </ListView>

请帮我解决这个问题提前谢谢

4

2 回答 2

2

是一个很好的教程,很好地解释了选择器的工作原理

于 2012-05-15T10:26:51.077 回答
1

我有rowback并且rowback_selected在我的可绘制文件夹中......

并使用android:state_focused, android:state_selected, android:state_pressed...

<item android:state_focused="true" android:drawable="@drawable/rowback" />
<item android:state_pressed="true" android:drawable="@drawable/rowback_selected" />
<item android:state_selected="true" android:state_focused="false"
    android:state_pressed="false" android:drawable="@drawable/rowback_selected" />
<item android:state_window_focused="false"
    android:drawable="@drawable/rowback" />
于 2012-05-15T10:13:48.760 回答