Forum Xamarin.Android

Help with custom ProgressBar

rpdbenrpdben Member ✭✭
edited May 2020 in Xamarin.Android

Hi,

I am using the latest version of Xamarin Forms and am trying to implement a ProgressBar with a custom renderer to change the height and corner radius.

My current code is pasted below but this is giving me the error ProgressBarRenderer.ProgressBarRenderer()' is obsolete: 'This constructor is obsolete as of version 2.5. Please use ProgressBarRenderer(Context) instead.

The exact same code in my iOS section of the project does not give me any errors. Any help on how to resolve would be much appreciated.

[assembly: ExportRenderer(typeof(Xamarin.Forms.ProgressBar), typeof(CustomProgressBarAndroid))]
namespace project.Droid
{
    public class CustomProgressBarAndroid : ProgressBarRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ProgressBar> e)
        {
            base.OnElementChanged(e);

            Control.ProgressTintColor = Color.FromHex("#F1881E").ToUIColor();
        }
    }
}

Best Answer

Answers

  • rpdbenrpdben Member ✭✭

    @LandLu Thank you for your response. This has been super helpful.

    Where can I find documentation for the Android methods (and iOS as well) for changing the progress bar? I need to also change the height, adjust the corner radius, and add text to the middle of the bar.

    Thanks!

  • LandLuLandLu Member, Xamarin Team Xamurai

    You could refer to the Android documentation about ProgressBar:
    https://developer.android.com/reference/android/widget/ProgressBar

Sign In or Register to comment.