0

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?

Donal Rafferty
  • 19,707
  • 39
  • 114
  • 191

1 Answers1

1

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.

CaseyB
  • 24,780
  • 14
  • 77
  • 112
  • Thats true but thats not an option, No text is to be on the buttons, graphics only – Donal Rafferty Jun 01 '11 at 17:16
  • You can still have the foreground be an image. Use an ImageButton and set the background as the background and the src as the foreground. http://stackoverflow.com/questions/2283444/android-image-button/2283993#2283993 – CaseyB Jun 01 '11 at 17:18
  • I presume that would mean redoing all the current images so that the foreground image contains whats to be displayed in the foreground on a transparent png? so that the background change can be seen through the foreground image? – Donal Rafferty Jun 01 '11 at 17:26