I tought to use OnTouchListener and tracking down and up events, setting then an alpha value, but I have to add this listener to all ImageButtons (they are really a lot). I wonder if there is a shortcut to achieve this result.
|
In case that when user click on button and this cause to change the opacity of that button you can do: In your
and in the
so, if you want to do the same process(change button opacity) for each button, so in the xml file for each button add the line
|
|||||||||||||||||||||
|
If you want to give users better expirince when clicking ImageButton, I recommend you to use selection drawable as the background of your ImageButtons. It gives better user experience, then setting opacity while performing click and it’s really easy to achieve. First you need to create in your drawable folder file with name f.e. image_button_selection.xml. In which you should define:
You should also put into drawable two png with alpha channel that will be displayed on focused button and pressed button. In this example they should be named respectively your_focused_background_drawable and your_pressed_background_drawable. When you do this you should in every use of your ImageButton in xml use following statement:
|
|||
|