我有5个文本视图。每个textview都在switch语句中,并在单击时执行方法调用。我希望在单击textview时更改文本颜色,并保持更改直到做出另一个选择。当前,我的代码在单击时仅更改颜色1秒钟,然后再次变回黑色。我需要它保持红色,直到单击另一个textview,然后它才能变回黑色。
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">
<item android:color="@color/colorPrimary" android:state_focused="true" android:state_pressed="false"/>
<item android:color="@color/colorPrimary" android:state_focused="true" android:state_pressed="true"/>
<item android:color="@color/colorPrimary" android:state_focused="false" android:state_pressed="true"/>
<item android:color="@color/colorPrimaryDark"/>
</selector>
JAVA代码:
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.moodLogToday:
retroFitToday();
break;
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.moodLogYesterday:
retroFitYesterday();
break;
XML:
<TextView
android:id="@+id/moodLogYesterday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yesterday"
android:textColor="@drawable/my_selector_pushed"
与另一个相同。