Steve Chadbourne
Steve Chadbourne

Reputation: 6953

Setting an Android Tint Color Pre Lollipop

I have written an Android custom renderer for a checkbox control.

I set the checkbox disabled color like so

Control.ButtonTintList = ColorStateList.ValueOf(element.DisabledColor.ToAndroid());

where Control is an Android.Widget.CheckBox

This does not work prior to Lollipop and I get an error

CheckboxRenderer.SetDisabledColor (Incident.UserControls.Checkbox element) Java.Lang.LinkageError: no method with name='setButtonTintList' signature='(Landroid/content/res/ColorStateList;)V' in class Landroid/widget/CompoundButton; no method with name='setButtonTintList' signature='(Landroid/content/res/ColorStateList;)V' in class Landroid/widget/CompoundButton;

I have found some mention of using DrawableCompat to do this but can't figure out how to do it in Xamarin/C#

Any ideas?

Upvotes: 0

Views: 506

Answers (1)

FreakyAli
FreakyAli

Reputation: 16449

using Android.Support.V7.Widget.AppCompactCheckbox instead of Your base Android.Widget.Checkbox might do the trick.

Also to change colour at runtime you could use this:

ViewCompat.SetBackgroundTintList(_YourView , ColorStateList.ValueOf(Color.ParseColor(Resources.GetString(Resource.Color.blueLine))));

Actually, the problem with things not working pre-lollipop is that Android KitKat is obsolete and so are the rest of the versions below so to have features that are new to Android you need to use the Appcompact library for backward compatibility.

Anyways, Goodluck! Happy coding

Upvotes: 1

Related Questions