I have 3 text views as shown below. Once I click on one of them, it turns to red but turns back to its default colour when I unselect it. I want to keep the selected TextView in red. I have these 3 TextViews in a fragment.
mQuickReturnView = (TextView) view.findViewById(R.id.footer);
mQuickReturnView1 = (TextView) view.findViewById(R.id.footer1);
mQuickReturnView2 = (TextView) view.findViewById(R.id.footer2);
TextView clickTextView = (TextView) view.findViewById(R.id.footer);
clickTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(), "I just clicked my textview!",Toast.LENGTH_LONG).show();
}
});
xml.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- not selected has transparent color -->
<item android:state_pressed="false" android:state_selected="false">
<color android:color="#D8000000"/>
</item>
<item android:state_pressed="true" >
<color android:color="#ff0000"/>
</item>
<item android:state_pressed="false" android:state_selected="true">
<color android:color="#ff0000"/>
</item>
</selector>
What should I change to keep it in red once selected.