如何改变选择的列表项的背景,机器人机器人、背景、列表

由网友(怎么骄傲怎么活)分享简介:我有两个的ListView 在我的活动,当我选择一个从第一列表数据将反映到其他列表。我已经为我做了这部分,其工作的罚款。但是我在努力改变的背景所选项目的第一个列表,我怎么能做到这一点? I have two ListView's in my Activity, when i select one from first...

我有两个的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> 

看一看这也。

阅读全文

相关推荐

最新文章