|
| 1 | +## Detailed documentation for ProgressButton library |
| 2 | + |
| 3 | +Quick setup can be found [here](Readme.md) |
| 4 | + |
| 5 | +## Showing Progress |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +```C# |
| 10 | +protected override void OnCreate(Bundle savedInstanceState) { |
| 11 | + base.OnCreate(savedInstanceState); |
| 12 | + SetContentView(Resource.Layout.activity_main); |
| 13 | + |
| 14 | + var myButton = FindViewById<MaterialButton>(Resource.Id.myButton); |
| 15 | + |
| 16 | + // It is mandatory to bind your button to activity or fragment lifecycle |
| 17 | + this.BindProgressButton(myButton); |
| 18 | + |
| 19 | + // (Optional) Enable fade in/out animations |
| 20 | + // All parameters are Optional (the Action itself is optional too) |
| 21 | + myButton.AttachTextChangeAnimator((textChangeAnimatorParams) => { |
| 22 | + textChangeAnimatorParams.FadeOutMills = 150; // current text fade out time in milliseconds. default 150 |
| 23 | + textChangeAnimatorParams.FadeInMills = 150; // current text fade in time in milliseconds. default 150 |
| 24 | + |
| 25 | + textChangeAnimatorParams.UseCurrentTextColor = false; // by default is true. handling text color based on the current color settings |
| 26 | + |
| 27 | + textChangeAnimatorParams.TextColor = Color.White; // override button text color with single color |
| 28 | + textChangeAnimatorParams.TextColorRes = Resource.Color.white; // override button text color with single color resource |
| 29 | + textChangeAnimatorParams.TextColorList = new ColorStateList(...); // override button text color with stateful color |
| 30 | + }); |
| 31 | + |
| 32 | + // Show progress with "Loading" text. The final progress size will be (radius + stroke) * 2 |
| 33 | + myButton.ShowProgress((progressParams) => { |
| 34 | + progressParams.ButtonText = "Loading"; // string value to show next to progress |
| 35 | + progressParams.ButtonTextRes = Resource.String.loading; // text resource to show next to progress |
| 36 | + |
| 37 | + // progress drawable gravity relative to button text |
| 38 | + // possible values TextStart, TextEnd and Center |
| 39 | + progressParams.Gravity = DrawableButton.Gravity.TextEnd; // default value is Gravity.TextEnd |
| 40 | + |
| 41 | + progressParams.TextMarginRes = Resource.Dimension.progressMargin; // margin between text and progress. default 10dp |
| 42 | + progressParams.TextMarginPx = 30; // margin between text and progress in pixels. default 10dp |
| 43 | + |
| 44 | + progressParams.ProgressColor = Color.White; // progress color int |
| 45 | + progressParams.ProgressColorRes = Resource.Color.white; // progress color resource |
| 46 | + progressParams.ProgressColors = new int[]{ Color.White, Color.Black }; // progress colors list |
| 47 | + |
| 48 | + |
| 49 | + progressParams.ProgressRadiusRes = Resource.Dimension.smallRadius; // progress radius dimension resource. default 7.5dp |
| 50 | + progressParams.ProgressRadiusPx = 50; // progress radius in pixels default 7.5dp |
| 51 | + |
| 52 | + progressParams.ProgressStrokeRes = Resource.Dimension.stroke3; // progress stroke dimension resource. default 2.5dp |
| 53 | + progressParams.ProgressStrokePx = 50; // progress stroke in pixels. default 2.5dp |
| 54 | + }); |
| 55 | + |
| 56 | + // Hide progress and show "Submit" text instead |
| 57 | + myButton.HideProgress(Resource.String.submit); |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +## Showing AnimatedDrawable |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +```C# |
| 66 | +protected override void OnCreate(Bundle savedInstanceState) { |
| 67 | + base.OnCreate(savedInstanceState); |
| 68 | + SetContentView(Resource.Layout.activity_main); |
| 69 | + |
| 70 | + var myButton = FindViewById<MaterialButton>(Resource.Id.myButton); |
| 71 | + |
| 72 | + // It is mandatory to bind your button to activity or fragment lifecycle |
| 73 | + this.BindProgressButton(myButton); |
| 74 | + |
| 75 | + // (Optional) Enable fade in/out animations |
| 76 | + // All parameters are Optional (the Action itself is optional too) |
| 77 | + myButton.AttachTextChangeAnimator((textChangeAnimatorParams) => { |
| 78 | + // same as Showing Progress above |
| 79 | + }); |
| 80 | + |
| 81 | + // setup bounds is required to use AnimatedDrawable with library |
| 82 | + var animatedDrawable = ContextCompat.GetDrawable(this, Resource.Drawable.animated_check); |
| 83 | + animatedDrawable.Bounds = new Rect(0, 0, 50, 50); |
| 84 | + |
| 85 | + myButton.ShowDrawable(animatedDrawable, (drawableParams) => { |
| 86 | + drawableParams.ButtonText = "Done"; // string value to show next to animated drawable |
| 87 | + drawableParams.ButtonTextRes = Resource.String.done; // text resource to show next to animated drawable |
| 88 | + |
| 89 | + // drawable gravity relative to button text |
| 90 | + // possible values TextStart, TextEnd and Center |
| 91 | + drawableParams.Gravity = DrawableButton.Gravity.TextEnd; // default value is Gravity.TextEnd |
| 92 | + |
| 93 | + drawableParams.TextMarginRes = Resource.Dimension.progressMargin; // margin between text and drawable. default 10dp |
| 94 | + drawableParams.TextMarginPx = 30; // margin between text and drawable in pixels. default 10dp |
| 95 | + }); |
| 96 | + |
| 97 | + // Hide drawable and show "Save" text instead |
| 98 | + myButton.HideDrawable(Resource.String.save); |
| 99 | +} |
| 100 | +``` |
0 commit comments