The following will result in a crash saying that cannot inflate the drawable.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:background="#000000" />
<item android:state_focused="true" android:background="#000000" />
<item android:background="#FFFFFF" />
</selector>
The solution is to change the background to use drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/grey" />
<item android:state_focused="true" android:drawable="@color/grey" />
<item android:drawable="@color/white" />
</selector>
android:drawable attribute does not accept raw color.
Define color.xml in res/values.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#000</color>
<color name="white">#fff</color>
<color name="grey">#cccccc</color>
</resources>
No comments:
Post a Comment