I’m trying to color an item’s (when selected) background. I’m working with the Android emulator. I have a set of XML files in res/drawable.
background.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/pressed" />
<item android:drawable="@drawable/normal" />
</selector>
normal.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#000000" />
</shape>
pressed.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#33ffff" />
</shape>
And my list_item.xml, with…my item :
<TextView ... android:background="@drawable/background" android:padding="6dp" />
Well, in the emulator state_pressed="true" works, however I want that the selected item remains colored. So, instead of state_pressed I tried state_activated …but hey…doesn’t works too. My item remains black…
Need some help 🙂 !
Thank you
Pls refer to the link below:
http://developer.android.com/resources/tutorials/views/hello-formstuff.html
try using state_focused for your case.
Thanks!