Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - different image for rollover on ImageButton

Is it possible to specify a different image when the user's focus comes to an ImageButton? I want to display an image button on a LinearLayout and change the image when the user's focus comes on the button or when the user presses the button.

Thanks.

like image 775
lostInTransit Avatar asked Mar 03 '09 14:03

lostInTransit


1 Answers

Yes, you can do this. What you need is a drawable xml file that defines a selector.

<selector xmlns:android...
  <item android:state_enabled="false" android:state_focused="true" android:drawable="..." />
  <item android:state_enabled="true" android:state_focused="false" android:drawable="..." />
</selector>

Then, use the id of this drawable XML when specifying the ImageButton in your layout XML.

like image 182
Nate Avatar answered Sep 22 '22 20:09

Nate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!