I'm attempting to change the background color of an Android TextView widget when the user touches it. I've created a selector for that purpose, which is stored in res/color/selector.xml and roughly looks like that:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:color="@color/semitransparent_white"
/>
<item
android:color="@color/transparent"
/>
</selector>
The clickable attribute of the TextView is "true", in case that's of interest.
When I assign this selector to a TextView as android:background="@color/selector", I'm getting the following exception at runtime:
ERROR/AndroidRuntime(13130): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #6: <item> tag requires a 'drawable' attribute or child tag defining a drawable
When I change the attribute to drawable, it works, but the result is looking completely wrong because the IDs appear to be interpreted as image references instead of color references (as the "drawable" suggests).
What confuses me is that I can set a color reference, e.g. "@color/black", as the background attribute directly. This is working as expected. Using selectors doesn't work.
I can also use the selector as the textColor without problems.
What's the correct way to apply a background-color-selector to a TextView in Android?
Thanksdb