我在ListSelector
添加了一个简单的ListView
。
问题是,只有在ListView滚动一点之后才会显示ListSelector
。
如何在选择时立即将ListSelector
设为apear?
的ListView
<ListView
android:id="@+id/contentListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_above="@id/buttonEntwerten"
android:scrollingCache="false"
android:cacheColorHint="#00000000"
android:listSelector="@drawable/list_selector"
/>
@绘制/ list_selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/list_selector__gradient_bg_hover" />
</selector>
答案 0 :(得分:-1)
你可以查看android如何配置它,并相应地更改它(文件名是&#34; list_selector_background.xml&#34;):
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:drawable="@color/transparent" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="true" android:drawable="@drawable/list_selector_background_focus" />
</selector>
简而言之,您只需要处理state_pressed状态。其余的都是处理好的状态。
代码中的问题是它没有状态。