【问题标题】:How to change Selected ListItem color如何更改选定的 ListItem 颜色
【发布时间】:2011-04-03 19:40:25
【问题描述】:

我有一个带有背景的列表视图。当我单击该列表视图的特定列表项时,我想更改该项的颜色。

我可以在关注列表项时更改颜色,但我想在用户单击该列表项时进行更改。

请帮忙...

【问题讨论】:

    标签: android-widget


    【解决方案1】:

    创建一个 selector_file_name.xml 并放置在可绘制文件夹上。该文件的内容(我将它与我的自定义可绘制/图像一起使用)。这个想法是你必须编辑 android:states_..... 用你自己的颜色或drawables/images。

    该文件的内容是

    < xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
     android:state_pressed="true" 
     android:drawable="@drawable/strishe_dhe_shigjete_bosh" />
    <item 
     android:state_selected="true" 
     android:drawable="@drawable/strishe_dhe_shigjete_bosh" />
    <item  
    android:drawable="@color/white"/>
    </selector>
    

    然后在主布局文件(有列表视图的地方)设置

    android:background="@drawable/selector_file_name"

    【讨论】:

      猜你喜欢
      • 2022-06-19
      • 1970-01-01
      • 2013-09-25
      • 2011-02-16
      • 1970-01-01
      • 2018-04-12
      • 2018-04-01
      • 2020-01-10
      • 1970-01-01
      相关资源
      最近更新 更多