o19830015 2013-02-28 08:57 采纳率: 12.5%
浏览 2019

点击之后text颜色没有改变

有一个listView,用selector设置条目背景。

list_selecter.xml :

<?xml version="1.0" encoding="utf-8"?>
<!-- focused and pressed -->
<item android:drawable="@color/darkred" android:state_pressed="true"/>
<item android:drawable="@android:color/transparent" android:state_pressed="false"/>
<!-- pressed -->
<item android:drawable="@color/darkred"/>

ListItem的布局文件:

 <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/list_selecter"
  android:orientation="vertical"
  android:padding="10dp" >

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/newsHeadingText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="20dp"
    android:textColor="@color/text_selector" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="5dp"
    android:background="@drawable/aerow" />


<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/newsText"
    android:layout_width="200dip"
    android:layout_height="wrap_content"
    android:layout_below="@id/newsHeadingText"
    android:textColor="#736F6E" />

</RelativeLayout>

但是颜色并没有发生改变,请指点迷津,谢谢。

  • 写回答

1条回答

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2022-12-19 14:53
    关注

    ChatGPT尝试为您解答,仅供参考
    看起来你的代码已经将 list_selecter.xml 作为背景设置给了 ListItem 布局文件中的 RelativeLayout 元素。


    但是,由于你提供的 list_selecter.xml 中没有定义任何背景色,因此 ListItem 布局文件中的 RelativeLayout 元素的背景色并没有改变。


    如果你想改变 ListItem 布局文件中的 RelativeLayout 元素的背景色,你可以在 list_selecter.xml 中定义背景色。例如:

    <?xml version="1.0" encoding="utf-8"?>
    <!-- focused and pressed -->
    <item android:drawable="@color/darkred" android:state_pressed="true"/>
    <item android:drawable="@color/gray" android:state_pressed="false"/>
    <!-- pressed -->
    <item android:drawable="@color/darkred"/>
    

    这样,当你按下 ListItem 布局文件中的 RelativeLayout 元素时,背景色将会变成 @color/darkred,当你放开时,背景色将会变成 @color/gray。

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器