Xamarin.Forms button: flash color when pressed

Similar to what was seen here in the documentation on the adaptive interaction of Google materials , I would like the button to respond to a click by flashing a color, but then gradually return to the original color.

Is it possible to achieve this effect using the default Xamarin.Forms Button control using the click handler method? Or should custom rendering be implemented to try to create this effect?

+4
source share
1 answer

You are looking for animation methods available on ui components. Essentially, you need to add a click handler to your button, which starts the animation (first change the color, then gradually darken using async / await). I added a link to a sample that animates resizing, but the theory remains 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();
    })
});
+7
source

All Articles