Jason Prado Jason Prado - 1 year ago 160
Android Question

Making a LinearLayout act like an Button

I have a LinearLayout that I've styled to look like a button, and it contains a few text/ImageView elements. I would like to make the whole LinearLayout act like a button, in particular to give it states that are defined in a so it has a different background when it is pressed.

Is there a better way than making an ImageButton the size of the whole Layout and positioning absolutely?

Answer Source

I ran into this problem just now. You'll have to set the LinearLayout to clickable. You can either do this in the XML with


Or in code with