Similar to what's being seen here in Google's Material Design Responsive Interaction documentation, I would like to have a button react to being pressed by flashing a color briefly but then returning to the original color gradually.
Can this effect be achieved using the default Xamarin.Forms Button control with a click handler method? Or must a custom renderer be implemented to try and create this effect?
You're looking for the animation methods available on ui components. Essentially you need to add a click handler to your button that runs animations (first your color change, then your gradual fade back using async/await). I have added a link to a sample that animates a size change, but the theory will remain the same.
// add a gester reco
this.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(async (o) =>
{
await this.ScaleTo(0.95, 50, Easing.CubicOut);
await this.ScaleTo(1, 50, Easing.CubicIn);
if (callback != null)
callback.Invoke();
})
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With