I have a TextView
whose background I would like to change when clicked on. I've tried following the many examples of this I've found on this site and others, but I can't seem to get it working properly.
I'm completely new to android development, so it's quite possible that I'm missing something obvious, so please bear with me. I'm also trying to do this through XML as opposed to Java.
Main.xml (contained within a table layout)
<TextView
android:id="@+id/character_option1"
android:text="Option1"
android:textColor="@color/text_off"
android:background="@drawable/selectors"
android:clickable="true"
android:padding="5dp" />
selectors.xml (in res/drawable)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:color="@drawable/option_on">
</item>
<item
android:color="@drawable/option_off" >
</item>
</selector>
colors.xml (in res/values)
<drawable name="option_on">#EBEBEB</drawable>
<drawable name="option_off">#CC0000</drawable>
I've also tried android:color="@color/option_off"
in selectors.xml with color name="option_off"
in res/values. And I tried simply putting android:color="#CC0000"
right into selectors.xml. None of it worked.
I'm not sure it's receiving any information from the selector in general. I set the default color to red #CC0000
just to check, but the background color is still the style's default white.
--
These are the most recent links I have tried as well:
Selector on background color of TextView