改变选择从橘子一个ListView绿 [英] Change Selection in a ListView from Orange to Green

查看:134
本文介绍了改变选择从橘子一个ListView绿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何做到这一点每个选中的列表项。

How do I do this per selected list item.

我尝试添加这安卓背景

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" 
        android:state_pressed="false"
        android:drawable="@color/android_green" />
    <item android:state_focused="true" 
        android:state_pressed="true"
        android:drawable="@color/black_alpha" />
    <item android:state_focused="false" 
        android:state_pressed="true"
        android:drawable="@color/black_alpha" />
    <item android:drawable="@color/white_alpha" />
</selector> 

但它不能正常工作,它改变了整个的ListView。

but it does not work, it changes the entire ListView.

仍然没有工作,这里是我迄今为止

Still not working, here is what I have so far

:: listview_background

::listview_background

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:drawable="@color/black_alpha" />
    <item android:drawable="@color/white_alpha" />  
</selector> 

::我认为,使用上述

::My view that is using the above

<ListView android:id="@+id/list" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:layout_below="@+id/round"
    android:listSelector="@drawable/listview_background">
</ListView>

的问题是,该black_alpha将应用整个列表,不只是选择的列表项目

The problem is that the black_alpha will apply the the entire list, not just the selected list item

推荐答案

下面是一个好文章如何使用带有选择列表。

Here's a good article on how to use selectors with lists.

而不是设置它是的android:背景在ListView的,我相信你想设置安卓listSelector ,如下所示:

Instead of setting it to be the android:background of the ListView, I believe you want to set android:listSelector as shown below:

<ListView android:id="@+id/list" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" 
      android:layout_gravity="center"
      android:divider="@null" 
      android:dividerHeight="0dip"
      android:listSelector="@drawable/list_selector" />

这篇关于改变选择从橘子一个ListView绿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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