I have an Android activity with an ImageButton. I would like to execute some logic when the button is clicked and show a different image for the pressed state, but also receive the touch event on the activity.
By default only the button receives the touch event. If I set the clickable attribute of the butto开发者_JAVA技巧n to false then only the activity receives the touch event.
What's the best way to implement the touch event in the activity and the click in the button?
Have the button call a method on the activity when it is clicked.
For lack of a better method, I overrode the touch event on the activity to execute the activity logic and detect if the touch was over the button, in which case I change its state and invoke the onClick logic.
精彩评论