Android - Multiple items in a statelist?

638 Views Asked by At

I currently have a keypad in my application 0 - 9, I require an on and off state for each button.

To do this I've used a StateList as follows:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="false"
        android:drawable="@drawable/dialpad_1_off" />

    <item android:state_pressed="true"
        android:drawable="@drawable/dialpad_1_on" />

</selector>

However this is only for one button, each button has a different on and off graphic, dialpad_2_off, dialpad_3_on etc...

So do I have to create a Statelist for every single button or is there a way to do it within one Statelist XML file?

1

There are 1 best solutions below

3
On BEST ANSWER

You could make the background of the image change state and use that common background for all of the buttons. Then you could use either text or an image as the button foreground.