Whats wrong with this xml, I am trying to get a button press feel. I am getting a exception, I am unable to understood. ResourceNotFound
In my layout.xm
The attribute android:background
does not exist. The correct way to do this is to first create a new resource file res/colors.xml
with the following contents:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="lt_gray">#AAAAAA</color>
<color name="dk_gray">#777777</color>
</resources>
Then just change your selector
to the following:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@color/lt_gray" />
<item android:state_pressed="true" android:drawable="@color/dk_gray" />
</selector>
This automatically creates a ColorDrawable and assigns it as the drawable for that state.
Once Try this
In selector state it is required to add drawable and in your case you wants to add color in selector state.So it is possible to create drawable using color in resource. It will work as ColorDrawable
Please check below code
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/clr_normal" android:state_pressed="false"/>
<item android:drawable="@drawable/clr_pressed" android:state_pressed="true"/>
</selector>
values/string.xml for color
<drawable name="clr_normal">#AAAAAA</drawable>
<drawable name="clr_pressed">#777777</drawable>