I have a button style defined like this:
<style name="button_style">
<item name="android:textColor">#ffffff</item>
<item name="android:background">@drawable/button_on_red</item>
</style>
I am wondering if I can setup a background image inside this like:
<style name="button_style">
<item name="android:background_when_pressed">@drawable/button_off_red</item>
<item name="android:textColor">#ffffff</item>
<item name="android:background">@drawable/button_on_red</item>
</style>
Thanks.
You’ll want to use what’s called a “statelist drawable”. You’d create the drawable as an xml file like this:
button_states.xml
For each state, you specify which drawable to use on the button. You then use this xml as the background for your button like so:
For details, checkout this documentation.