/
MaterialCheckBoxRenderer.cs
46 lines (40 loc) · 1.51 KB
/
MaterialCheckBoxRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using Android.Content;
using Android.Content.Res;
using Xamarin.Forms.Platform.Android;
using AColor = Android.Graphics.Color;
#if __ANDROID_29__
using AColorUtils = AndroidX.Core.Graphics.ColorUtils;
#else
using AColorUtils = Android.Support.V4.Graphics.ColorUtils;
#endif
using AAttribute = Android.Resource.Attribute;
using Android.Graphics.Drawables;
using Android.Graphics;
namespace Xamarin.Forms.Material.Android
{
public class MaterialCheckBoxRenderer : CheckBoxRendererBase
{
static int[][] _checkedStates = new int[][]
{
new int[] { AAttribute.StateEnabled, AAttribute.StateChecked },
new int[] { AAttribute.StateEnabled, -AAttribute.StateChecked },
new int[] { -AAttribute.StateEnabled, AAttribute.StateChecked },
new int[] { -AAttribute.StateEnabled, -AAttribute.StatePressed }
};
public MaterialCheckBoxRenderer(Context context) : base(MaterialContextThemeWrapper.Create(context), Resource.Attribute.materialCheckBoxStyle)
{
}
protected override ColorStateList GetColorStateList()
{
if (Element.Color != Color.Default)
return base.GetColorStateList();
int[] checkBoxColorsList = new int[4];
checkBoxColorsList[0] = MaterialColors.GetCheckBoxColor(true, true);
checkBoxColorsList[1] = MaterialColors.GetCheckBoxColor(false, true);
checkBoxColorsList[2] = MaterialColors.GetCheckBoxColor(true, false);
checkBoxColorsList[3] = MaterialColors.GetCheckBoxColor(false, false);
return new ColorStateList(_checkedStates, checkBoxColorsList);
}
}
}