I want to display progress bar with rounded corners in Xamarin forms. I was able to do it in iOS using a custom renderer:
class CustomProgressBarRenderer: ProgressBarRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ProgressBar> e)
{
base.OnElementChanged(e);
Control.ProgressTintColor = Color.FromRgb(255, 201, 74).ToUIColor();
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
var X = 1.0f;
var Y = 7.0f;
CGAffineTransform transform = CGAffineTransform.MakeScale(X, Y);
this.Transform = transform;
this.ClipsToBounds = true;
this.Layer.MasksToBounds = true;
this.Layer.CornerRadius = 5; // This is for rounded corners.
}
}
How can I achieve the same in Android? This is how I want the progress bar(rounded corners) to look.
You could add a
Drawable
on your androidProgressBar
to implement this feature.Set the style for your
ProgressBar
, Drawable\bar_color.xml :Drawable\progress_bar_background.xml :
Drawable\shape_progressbar_progress.xml :
Using it in your
CustomProgressBarRenderer
:Effect :