我正在使用此代码表在不同的事件中定义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>
答案 0 :(得分: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>
答案 1 :(得分:0)
在xml文件中,要想要更改颜色的textview,请添加
android:background="@drawable/filename"