Custom Renderer with android XML drwabale and binding

FrancoisMFrancoisM FRUniversity ✭✭

Hi,

I've looked around and found how to use an xml drawable and use SetBackgroundDrawable in an android custom renderer. However, how do I change say a color of that xml within a PropertyChanged Handler?
Or said differently, how to bind xml drawables?
Tks.

François

Tagged:

Answers

  • FrancoisMFrancoisM FRUniversity ✭✭

    Found:
    https://forums.xamarin.com/discussion/12681/programmatically-change-the-solid-color-in-xml

    So I tried

        var bgDrawable = (LayerDrawable)Control.Background;
                    var bgShape = (GradientDrawable)bgDrawable.FindDrawableByLayerId(Resource.Id.progress);
                    bgShape.SetColor(element.BarColor.ToAndroid());
    

    but Control.Background is null (while I called SetBackgroundDrawable just before).

    Then I tried

    var inflater = Forms.Context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;
                var bar = inflater.Inflate(Resource.Drawable.ProgressBar, null);
                var bgDrawable = (LayerDrawable)bar.Background;
                var bgShape = (GradientDrawable)bgDrawable.FindDrawableByLayerId(Resource.Id.progress);
                bgShape.SetColor(element.BarColor.ToAndroid());
    

    but had an error on inflate.

Sign In or Register to comment.