Android Selector Problem
i have a listview with a custom item_row.xml. I've defined a selector in this way:
<?xml version="1.0" encoding="utf-8"?>
<item
android:state_pressed="false"
android:drawable="@drawable/list_bg" >
</item>
<item
android:state_pressed="true"
android:drawable="@drawable/header_bg" >
</item>
<item
android:state_focused="false"
android:drawable="@drawable/list_bg" >
</item>
<item
android:state_focuse开发者_StackOverflow社区d="true"
android:drawable="@drawable/header_bg">
</item>
and then put into item_row.xml in this way:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="70dip"
android:orientation="vertical"
android:background="@drawable/list_selector">
I want 2 things:
- When i move with arrow keys, the item selected changed its background. It's works fine with the actual implementation of selector.
- When i press a item, the item changed its background too, but it doesn't work with the actual selector.
Any idea? I try to set also into the ListView android:listSelector="@drawable/list_selector" but it doesn't work neither.
Thanks
You should model your StateListDrawable
after the one used by Android itself for ListView
selectors. You can find this in $ANDROID_HOME/platforms/$VERSION/data/res/drawable/list_selector_background.xml
, where $ANDROID_HOME
is where your Android SDK is installed and $VERSION
is some Android version (e.g., android-2.1
). Then, apply the list selector via android:listSelector
in the ListView
in your layout XML.
精彩评论