Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms Button: Flash Color on Press

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?

like image 759
chriszumberge Avatar asked Jun 22 '15 20:06

chriszumberge


1 Answers

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();
    })
});
like image 118
Will Decker Avatar answered Oct 11 '22 21:10

Will Decker