From e079c1959f3512de5f86ff333529e390f46a68be Mon Sep 17 00:00:00 2001 From: Garth Smedley Date: Sat, 16 Dec 2017 11:58:36 -0400 Subject: [PATCH] Set tint colors based on control state. --- checkbox.android.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/checkbox.android.ts b/checkbox.android.ts index 541e600..3c5fc77 100644 --- a/checkbox.android.ts +++ b/checkbox.android.ts @@ -134,10 +134,33 @@ export class CheckBox extends View implements CheckBoxInterface { } set fillColor(color: string) { (this.style).fillColor = color; - if (this._android && device.sdkVersion >= "21") { - this._android.setButtonTintList( - android.content.res.ColorStateList.valueOf(new Color(color).android) - ); + if (this._android) { + let colorDef = new Color(color).android; + if (device.sdkVersion == "21") { + this._android.setButtonTintList( + android.content.res.ColorStateList.valueOf(colorDef) + ); + } else if (device.sdkVersion > "21") { + let Arr: any = Array; + let stateArray = Arr.create("[I", 2); + stateArray[0] = Arr.create("int", 1); + stateArray[1] = Arr.create("int", 1); + stateArray[0][0] = -android.R.attr.state_checked; + stateArray[1][0] = android.R.attr.state_checked; + let colorArray = Arr.create("int", 2); + colorArray[0] = android.graphics.Color.GRAY; + colorArray[1] = colorDef; + let colorStateList = new android.content.res.ColorStateList( + stateArray, + colorArray + ); + this._android.setButtonTintList(colorStateList); + } else { + android.support.v4.widget.CompoundButtonCompat.setButtonTintList( + this._android, + android.content.res.ColorStateList.valueOf(colorDef) + ); + } } }