コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: CheckBoxExtensions.cs プロジェクト: Glepooek/maui
        public static void UpdateForeground(this AppCompatCheckBox platformCheckBox, ICheckBox check)
        {
            var mode = PorterDuff.Mode.SrcIn;

            CompoundButtonCompat.SetButtonTintList(platformCheckBox, platformCheckBox.GetColorStateList(check));
            CompoundButtonCompat.SetButtonTintMode(platformCheckBox, mode);
        }
コード例 #3
0
		void UpdateOnColor()
		{
			if (Element == null || Control == null)
				return;

			var mode = PorterDuff.Mode.SrcIn;

			CompoundButtonCompat.SetButtonTintList(Control, GetColorStateList());
			CompoundButtonCompat.SetButtonTintMode(Control, mode);
		}
コード例 #4
0
        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);
            }
        }