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

发布于 2024-09-25 04:24:33 字数 1206 浏览 6 评论 0原文

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

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 时,什么也没有出现。

I have the following ListView, and have followed the answer from this SO Question w/ no luck:

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

Here is my 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>

When I press down on a ListViewItem nothing appears.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

颜漓半夏 2024-10-02 04:24:33

Alam,使用此代码:

list_selector.xmlgradient_bg.xmlgradient_bg_hover.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>

-

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

Sheehan

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

Sheehan Alam, use this code:-

list_selector.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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文