Skip to content Skip to sidebar Skip to footer

Have A Button Execute Onclicklistener On End Of Ripple Animation(material Theme)

I'm observing a bug with ripple animation on a button in Android. Basically, I have a ViewGroup, call it ButtonContainer that contains 2 buttons, call them OkButton and CancelButto

Solution 1:

The short answer: not really and according to the Material guidelines (AFAIK) you shouldn't delay the onClick execution in such a way. In my opinion it would result in pretty poor UX - I like my buttons snappy and I don't like waiting for fancy animations.

The medium-length semi-answer: you could do a quick hack and wrap the meat of your onClick logic in a .postDelayed(...) call with a good enough delay. With a proper delay, the action would happen after the ripple. It is a hack, it is brittle and I would advise you against this solution.

The long answer: you can actually determine if the Ripple has finished animating, though that path is a bit complicated. Ripple is a Drawable, and as all animating Drawables, it tells its View when to do animation (and when to finish it) with a callback. You could tap into this callback to tell when the animation actually finished.

E.g. you could implement your own callback for this that forwards all calls to the Ripple's hosting ViewGroup and also tell you when the animation has finished so you can do business.

As the bottom line, I think that you should either:

  • Solve this problem as the article does that you linked
  • Just forget about the Ripple effect in this case if that's an option.

Post a Comment for "Have A Button Execute Onclicklistener On End Of Ripple Animation(material Theme)"