问题设置ListView中选择颜色时,pressed [英] Problem setting ListView selector color when pressed

查看:130
本文介绍了问题设置ListView中选择颜色时,pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下ListView控件,并且遵循了这太问题的答案瓦特/没有运气:

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

<一个href="http://stackoverflow.com/questions/2038040/android-listview-selector-color">http://stackoverflow.com/questions/2038040/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>

当我preSS倒在ListViewItem的什么也没有。

When I press down on a ListViewItem nothing appears.

推荐答案

希恩阿拉姆,使用code: -

Sheehan Alam, use this code:-

list_selector.xml

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

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

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>

这篇关于问题设置ListView中选择颜色时,pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆