public static void UpdateForeground(this AppCompatCheckBox nativeCheckBox, ICheckBox check) { // TODO: Delete when implementing the logic to set the system accent color. Graphics.Color accent = Graphics.Color.FromArgb("#ff33b5e5"); var targetColor = accent; // For the moment, we're only supporting solid color Paint for the Android Checkbox if (check.Foreground is SolidPaint solid) { targetColor = solid.Color; } var tintColor = targetColor.ToNative(); var tintList = new ColorStateList( CheckedStates, new int[] { tintColor, tintColor, tintColor, tintColor }); var tintMode = PorterDuff.Mode.SrcIn; CompoundButtonCompat.SetButtonTintList(nativeCheckBox, tintList); CompoundButtonCompat.SetButtonTintMode(nativeCheckBox, tintMode); }
private void CheckboxPropertyChanged(Checkbox model, String propertyName) { if (propertyName == null || Checkbox.IsCheckedProperty.PropertyName == propertyName) { checkBox.Checked = model.IsChecked; } if (propertyName == null || Checkbox.ColorProperty.PropertyName == propertyName) { int[][] states = { new int[] { Android.Resource.Attribute.StateEnabled }, // enabled new int[] { -Android.Resource.Attribute.StateEnabled }, // disabled new int[] { Android.Resource.Attribute.StateChecked }, // unchecked new int[] { Android.Resource.Attribute.StatePressed } // pressed }; var checkBoxColor = (int)model.Color.ToAndroid(); int[] colors = { checkBoxColor, checkBoxColor, checkBoxColor, checkBoxColor }; CompoundButtonCompat.SetButtonTintList(checkBox, new ColorStateList(states, colors)); } if (propertyName == null || Checkbox.ScaleCheckboxProperty.PropertyName == propertyName) { checkBox.ScaleX = (float)model.ScaleCheckbox; checkBox.ScaleY = (float)model.ScaleCheckbox; } }
public static void UpdateForeground(this AppCompatCheckBox platformCheckBox, ICheckBox check) { var mode = PorterDuff.Mode.SrcIn; CompoundButtonCompat.SetButtonTintList(platformCheckBox, platformCheckBox.GetColorStateList(check)); CompoundButtonCompat.SetButtonTintMode(platformCheckBox, mode); }
void UpdateOnColor() { if (Element == null || Control == null) return; var mode = PorterDuff.Mode.SrcIn; CompoundButtonCompat.SetButtonTintList(Control, GetColorStateList()); CompoundButtonCompat.SetButtonTintMode(Control, mode); }
public void ApplyStyle(object element) { //checkBox?.Background.SetColorFilter(Color.ParseColor(AppColors.Blue), PorterDuff.Mode.SrcOut); ////checkBox.BackgroundTintList. = Color.Black; //var colors = new[] { Resource.Color.blue }; //var state = new[] { Android.Resource.Attribute.StateChecked }; //var states = new int[][] { state }; //var colorList = new ColorStateList(states, colors); if (element is CheckBox checkBox) { CompoundButtonCompat.SetButtonTintList(checkBox, ContextCompat.GetColorStateList(Application.Context, Resource.Color.blue)); } }
private void UpdateOnColor() { if ((Element as IS.Toolkit.XamarinForms.Controls.CheckBox) == null || Control == null) { return; } var mode = PorterDuff.Mode.SrcIn; var stateChecked = global::Android.Resource.Attribute.StateChecked; var stateEnabled = global::Android.Resource.Attribute.StateEnabled; var uncheckedDefault = Android.Graphics.Color.Gray; var disabledColor = Android.Graphics.Color.LightGray; var list = new ColorStateList( new int[][] { new int[] { -stateEnabled, stateChecked }, new int[] { stateEnabled, stateChecked }, new int[] { stateEnabled, -stateChecked }, new int[] { }, }, new int[] { disabledColor, Element.CheckedColor == Xamarin.Forms.Color.Default ? Xamarin.Forms.Color.Accent.ToAndroid() : Element.CheckedColor.ToAndroid(), Element.UncheckedColor == Xamarin.Forms.Color.Default ? uncheckedDefault : Element.UncheckedColor.ToAndroid(), disabledColor, }); if (IsLollipopOrNewer) { Control.ButtonTintList = list; Control.ButtonTintMode = mode; } else { CompoundButtonCompat.SetButtonTintList(Control, list); CompoundButtonCompat.SetButtonTintMode(Control, mode); } }