bloudermilk
bloudermilk

Reputation: 18109

Down state on clickable TextView

I have a clickable TextView with a drawable as its background. I'm looking for the right way to implement a down-state drawable so the background changes when the user presses down. I have been able to almost perfectly replicate this behavior by listening for MotionEvents and changing the background when the user is pressing down.. The only thing that doesn't match up with system-wide down state behavior here is that if the user keeps holding down and moves their finger off the button, the state remains down until they release their finger from the screen... whereas in Maps overlays or Buttons or ListViews or anything else the state immediately goes back to off when the finger moves from the object.

I know there must be some proper way to go about doing this... A nudge in the right direction would be great!

Thanks, Nick

Upvotes: 1

Views: 658

Answers (1)

Mark B
Mark B

Reputation: 200607

You need to use a Selector for the background. I'm not sure if there is an official example of how to use Selectors, but I found this site that seems to have a pretty good example:

http://www.craiget.com/2009/03/restyling-android-imagebuttons/

That should get you on the right track.

Edit: Apparently that first link is down, until/unless it comes back here is another example: http://www.mkyong.com/android/android-imagebutton-selector-example/

Upvotes: 2

Related Questions