【发布时间】:2010-02-02 11:02:26
【问题描述】:
我有一个像这样的列表选择器的简单列表。
<ListView android:id="@+id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_below="@+id/round"
android:listSelector="#99000000" android:clickable="true" android:cacheColorHint="#00000000" android:background="#00000000">
</ListView>
如您所见 android:listSelector="#99000000" 但“黑色 alpha”颜色应用于整个列表,而不是所选项目。
这就是我现在拥有的,但整个列表仍然变黑
::listview_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="@drawable/list_normal" />
<item android:state_pressed="true"
android:drawable="@drawable/list_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/list_active" />
</selector>
::colors.xml
<resources>
<drawable name="list_normal">#96FFFFFF</drawable>
<drawable name="list_active">#66000000</drawable>
<drawable name="list_pressed">#CA000000</drawable>
</resources>
::我列表中的 xml 标签
android:listSelector="@drawable/listview_background"
【问题讨论】:
-
我应该将选择器的文件放在哪个文件夹中?
-
在 HoneyComb 之前的所有版本中都有一个错误,它将列表选择器 color 应用于整个列表背景。 Check out my answer to another question 了解更多详情。使用图像作为背景不是问题,因此可以使用以下所有解决方法。
标签: android