|
| 1 | +# Progress Button for Xamarin.Android - Ported from [this](https://github.com/razir/ProgressButton) library |
| 2 | +[](https://github.com/XamarinDeveloper/ProgressButton/releases) |
| 3 | +[](https://www.nuget.org/packages/Ir.XamarinDev.Android.ProgressButton/) |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +#### Article on ProAndroidDev.com explaining how it works (in kotlin) : [here](https://proandroiddev.com/replace-progressdialog-with-a-progress-button-in-your-app-14ed1d50b44) |
| 12 | + |
| 13 | + |
| 14 | +#### Add progress animation to any button by adding a few lines of code without layout changes |
| 15 | + |
| 16 | +### Main features: |
| 17 | + - No layout changes required |
| 18 | + - Few lines of code to add |
| 19 | + - Easily configurable |
| 20 | + - Customizable |
| 21 | + - Built in fade animations |
| 22 | + |
| 23 | +## NuGet package |
| 24 | +``` |
| 25 | +Install-Package Ir.XamarinDev.Android.ProgressButton |
| 26 | +``` |
| 27 | + |
| 28 | +## How to use |
| 29 | + |
| 30 | +### Basic example |
| 31 | + |
| 32 | +```C# |
| 33 | +protected override void OnCreate(Bundle savedInstanceState) { |
| 34 | + base.OnCreate(savedInstanceState); |
| 35 | + SetContentView(Resource.Layout.activity_main); |
| 36 | + |
| 37 | + var myButton = FindViewById<MaterialButton>(Resource.Id.myButton); |
| 38 | + |
| 39 | + // bind your button to activity lifecycle |
| 40 | + this.BindProgressButton(myButton) |
| 41 | + |
| 42 | + // (Optional) Enable fade in/out animations |
| 43 | + myButton.AttachTextChangeAnimator() |
| 44 | + |
| 45 | + // Show progress with "Loading" text |
| 46 | + myButton.ShowProgress((progressParams) => { |
| 47 | + progressParams.ButtonTextRes = Resource.String.loading; |
| 48 | + progressParams.ProgressColor = Color.White; |
| 49 | + }); |
| 50 | + |
| 51 | + // Hide progress and show "Submit" text instead |
| 52 | + myButton.HideProgress(Resource.String.submit) |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### Showing AnimatedDrawable |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +```C# |
| 61 | +var animatedDrawable = ContextCompat.GetDrawable(this, Resource.Drawable.animated_check); |
| 62 | +// Defined bounds are required for your drawable |
| 63 | +animatedDrawable.Bounds = new Rect(0, 0, 40, 40); |
| 64 | + |
| 65 | +button.ShowDrawable(animatedDrawable, (drawableParams) => { |
| 66 | + buttonTextRes = Resource.String.saved; |
| 67 | +}); |
| 68 | +``` |
| 69 | + |
| 70 | +### Detailed doc: [here](DetailedDoc.md) |
| 71 | + |
| 72 | +### Avoiding memory leaks |
| 73 | +To avoid memory leaks you always need to bind your button to a LifecycleOwner (usually Activity, or Fragment): |
| 74 | + |
| 75 | +```C# |
| 76 | +[ILifecycleOwner].BindProgressButton(button) |
| 77 | +``` |
| 78 | + |
| 79 | +### Author |
| 80 | +XamarinDev |
| 81 | + |
| 82 | +### Credits |
| 83 | +Anton Hadutski - [GitHub](https://github.com/razir) |
0 commit comments