gpt4 book ai didi

android - 按下时设置 ListView 选择器颜色时出现问题

转载 作者:太空宇宙 更新时间:2023-11-03 10:31:49 26 4
gpt4 key购买 nike

我有以下 ListView,并且没有运气就遵循了这个 SO 问题的答案:

Android ListView Selector Color

<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ARListView"
android:background="@drawable/transparent_background"
android:cacheColorHint="#00000000"
android:listSelector="@drawable/ar_selector"
android:drawSelectorOnTop="true">

这是我的 ar_selector.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="@android:color/transparent" />
<item android:state_pressed="true"
android:drawable="@color/solid_red" />
<item android:state_focused="true"
android:drawable="@android:color/transparent" />
</selector>

当我按下 ListViewItem 时,什么也没有出现。

最佳答案

Sheehan Alam,使用此代码:-

列表选择器.xml

  <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/gradient_bg" />

<item android:state_pressed="true"
android:drawable="@drawable/gradient_bg_hover" />

<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/gradient_bg_hover" />
</selector>

gradient_bg.xml

 <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#f1f1f2"
android:centerColor="#e7e7e8"
android:endColor="#cfcfcf"
android:angle="270" />
</shape>

gradient_bg_hover.xml

  <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#18d7e5"
android:centerColor="#16cedb"
android:endColor="#09adb9"
android:angle="270" />
</shape>

关于android - 按下时设置 ListView 选择器颜色时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3817776/

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