Reputation: 19824
I wish to change the image of a button when it is pressed. I am doing so in a selector XML file which is fine, and seems the same in all of the examples I have seen so far.
Am I correct though in saying that a separate XML file is required for EVERY button? I have one activity with 6 buttons, so does that mean in order to represent each of those buttons being pressed, I need 6 XML files?
That seems very cumbersome so maybe someone can shed some light on the best way to do it.
Here are the images I want to use for pressed
:
Not pressed
:
Upvotes: 0
Views: 256
Reputation: 6940
If you want all the buttons to look the same, you'll only need one XML file to define the appearance of the button. You can use that same appearance for as many imagebuttons as you like. If you want the same background, but different icons you still only need one selector file, but the images you feed it should just be the red and blue squares, with no question mark. Then, as the src for the imagebutton, you would put the transparent image of just the question mark, just the clock, just the euro, etc
Upvotes: 2
Reputation: 82563
No. You just need to define your State Selector list once, and can reuse it for as many Views as you like (assuming you want them all to look the same).
Upvotes: 1