Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

ProgressBar Colour Android API Level < 21

To give my progress bar a background colour I had to create a custom renderer in which I call:

Control.ProgressTintList = Android.Content.Res.ColorStateList.ValueOf(color.ToAndroid());

However when this runs on Android versions pre API level 21, ProgressTintList method is not found.

How can I go about having a ProgressBar with a colour pre API level 21?


  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Couldn't you have just set the background color in the materials theme.xml of your android project? Seems like a lot less work.

  • darrell.tunnelldarrell.tunnell USMember ✭✭
    edited January 2018

    Ok I have found an answer.

    In the renderer

                    if (_isTintSupported)
                        //  ProgressTintList is only available >= api level 21.
                        Control.ProgressTintList = Android.Content.Res.ColorStateList.ValueOf(androidColor);
                        Drawable progressDrawable = Control.ProgressDrawable.Mutate();
                        progressDrawable.SetColorFilter(androidColor, Android.Graphics.PorterDuff.Mode.SrcIn);
                        Control.ProgressDrawable = progressDrawable;

    Where _isTintSupported is defined as:

       private static readonly bool _isTintSupported = Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.Lollipop;
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Thanks for sharing the solution. Not enough people do that for their own questions but it really is what makes the coding community a community.

Sign In or Register to comment.