开发者

Selector for custom list view "Change ListView background - strange behaviour"

开发者 https://www.devze.com 2023-02-10 13:13 出处:网络
I am using this tutorials and I want to a开发者_如何学Cdd selectors for this list view. I tried some codes but it doest work. How can I do it.

I am using this tutorials and I want to a开发者_如何学Cdd selectors for this list view. I tried some codes but it doest work. How can I do it.

I used code as list_selector.xml

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

    <item android:state_focused="true"
        android:drawable="@drawable/list_selector_background_focus" />
    <item android:state_pressed="true"
        android:drawable="@drawable/list_selector_background_pressed" />

</selector>

and my List view

<ListView
              android:id="@+id/select_names_tags_lv"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:listSelector="@drawable/list_selector"
              android:layout_alignParentTop="false"
              android:layout_gravity="center_vertical">
            </ListView>


Just change a word here from listSelector to background. Because you want it as the background drawable selector, right?

        <ListView
          android:id="@+id/select_names_tags_lv"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
                android:background="@drawable/list_selector"
          android:layout_alignParentTop="false"
          android:layout_gravity="center_vertical">
        </ListView>

EDIT:

try changing your selector file to (I changed the order of the two items):

<?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_background_pressed" />
    <item android:state_focused="true"
        android:drawable="@drawable/list_selector_background_focus" />
</selector>
0

精彩评论

暂无评论...
验证码 换一张
取 消