2012-05-28 89 views
0

我使用此代碼表來定義不同事件中的textView顏色。 textView在listView中(10+項),效果(顏色)適用於每個listItem中的每個textView。我如何才能更改僅按下的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> 
+0

?以及什麼顏色,當它沒有按下? – FoamyGuy

回答

0

在XML文件中,你想改變顏色的TextView,添加

android:background="@drawable/filename" 
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> 
你想被按下時,它是什麼顏色