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。

    评论

报告相同问题?

悬赏问题

  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题