如何改变选择的列表项的背景,机器人 [英] how to change selected list item background, android

查看:97
本文介绍了如何改变选择的列表项的背景,机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个的ListView 在我的活动,当我选择一个从第一列表数据将反映到其他列表。我已经为我做了这部分,其工作的罚款。但是我在努力改变的背景所选项目的第一个列表,我怎么能做到这一点?

I have two ListView's in my Activity, when i select one from first List data will reflected to other list. I have done this part, its working fine for me. But I am struggling to change the background for selected item in first List, how can i do this?

推荐答案

您可以通过下面的做到这一点 -

You can do this by below -

设置安卓listSelector =@可绘制/选择您的ListView的XML属性。而且,在你的 selection.xml 包含了将持有的变化,当您从列表视图中选择任何项目的选择。

Set the android:listSelector="@drawable/selection" to your ListView's xml attribute. And, in your selection.xml contains the selector which will hold the change when you select any item from listview.

selection.xml

<?xml version="1.0" encoding="utf-8"?>
<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> 

看一看也。

这篇关于如何改变选择的列表项的背景,机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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