gpt4 book ai didi

android - ListSelector 适用于整个列表

转载 作者:IT王子 更新时间:2023-10-28 23:46:38 26 4
gpt4 key购买 nike

我有一个像这样的列表选择器的简单列表。

<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"

最佳答案

我遇到了同样的问题,在查看其中一个平台可绘制 XML 文件时,我注意到一种方法可以通过在 XML 中创建形状来消除仅为颜色创建图像文件的需要。

例如,而不是:

<item android:state_focused="true"
android:drawable="@drawable/list_active" />

做:

<item android:state_focused="true">
<shape>
<solid android:color="#66000000" />
</shape>
</item>

除了创建一个纯色的drawable之外,它的形状是灵活的,类似于一个简单的矢量对象。所有详细信息都可以在这里找到:http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

关于android - ListSelector 适用于整个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2183447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com