Skip to content

XamarinDeveloper/ProgressButton

Repository files navigation

Progress Button for Xamarin.Android - Ported from this library

Release NuGet

basic progress button example

progress cebter button example

mixed progress button example

Article on ProAndroidDev.com explaining how it works (in kotlin): here

Add progress animation to any button by adding a few lines of code without layout changes

Main features:

  • No layout changes required
  • Few lines of code to add
  • Easily configurable
  • Customizable
  • Built in fade animations

NuGet package

Install-Package Ir.XamarinDev.Android.ProgressButton 

How to use

Basic example

protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); var myButton = FindViewById<MaterialButton>(Resource.Id.myButton); // bind your button to activity lifecycle this.BindProgressButton(myButton); // (Optional) Enable fade in/out animations  myButton.AttachTextChangeAnimator(); // Show progress with "Loading" text myButton.ShowProgress((progressParams) => { progressParams.ButtonTextRes = Resource.String.loading; progressParams.ProgressColor = Color.White; }); // Hide progress and show "Submit" text instead myButton.HideProgress(Resource.String.submit); }

Showing AnimatedDrawable

animated drawable button example

var animatedDrawable = ContextCompat.GetDrawable(this, Resource.Drawable.animated_check); // Defined bounds are required for your drawable  animatedDrawable.Bounds = new Rect(0, 0, 40, 40); button.ShowDrawable(animatedDrawable, (drawableParams) => { buttonTextRes = Resource.String.saved; });

Detailed doc: here

Avoiding memory leaks

To avoid memory leaks you always need to bind your button to a LifecycleOwner (usually Activity, or Fragment):

[ILifecycleOwner].BindProgressButton(button);

License

GPL v3.0

Author

XamarinDev

Credits

Anton Hadutski - GitHub

About

Make any button a ProgressButton with just a few lines of code

Topics

Resources

License

Stars

Watchers

Forks

Languages