0

我正在使用此代码表在不同事件中定义 textView 的颜色。textView 在 listView 中(10+ 项),效果(颜色)适用于每个 listItem 中的每个 textView。如何更改仅按下的 textView 的颜色?

<?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="true"
    android:color="@color/text_white" />
  <item
    android:state_focused="false"
    android:state_pressed="true"
    android:color="@color/text_white" />
  <item
    android:state_focused="true"
    android:color="@color/text_white" />
  <item
    android:state_selected="true"
    android:color="@color/text_white" />
  <item
    android:state_checked="true"
    android:color="@color/text_white" />
  <item
    android:state_selected="false"
    android:state_checked="false"
    android:state_focused="false"
    android:state_pressed="false"
    android:color="@color/text_blue" />
</selector>
4

2 回答 2

1

尝试这个

   <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" //<<<<<Here focus us true then txt_pressed
          android:state_pressed="false" 
          android:drawable="@drawable/txt_pressed" />
    <item android:state_focused="true" 
          android:state_pressed="true"
          android:drawable="@drawable/txt_pressed" />
    <item android:state_focused="false" 
          android:state_pressed="true"
      android:drawable="@drawable/txt_pressed" />
    <item android:drawable="@drawable/txt_default" />
</selector>
于 2012-05-29T05:20:52.520 回答
0

在xml文件中,要更改颜色的textview,添加

 android:background="@drawable/filename" 
于 2012-05-29T05:12:41.660 回答