diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/SwitchProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/SwitchProxy.java index a3aeeb14921..a96e30f2de2 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/SwitchProxy.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/SwitchProxy.java @@ -25,7 +25,9 @@ TiC.PROPERTY_TEXT_ALIGN, TiC.PROPERTY_TINT_COLOR, TiC.PROPERTY_ACTIVE_TINT_COLOR, - TiC.PROPERTY_VERTICAL_ALIGN + TiC.PROPERTY_VERTICAL_ALIGN, + TiC.EVENT_PROPERTY_ACTIVE_THUMB_COLOR, + TiC.EVENT_PROPERTY_THUMB_COLOR }) public class SwitchProxy extends TiViewProxy { diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISwitch.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISwitch.java index 96fc99a63e9..b72f730193a 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISwitch.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISwitch.java @@ -64,6 +64,34 @@ public void processProperties(KrollDict d) setStyle(TiConvert.toInt(d.get(TiC.PROPERTY_STYLE), UIModule.SWITCH_STYLE_SLIDER)); } + if (d.containsKeyAndNotNull(TiC.EVENT_PROPERTY_THUMB_COLOR) + || d.containsKeyAndNotNull(TiC.EVENT_PROPERTY_ACTIVE_THUMB_COLOR)) { + CompoundButton currentButton = (CompoundButton) getNativeView(); + if (currentButton instanceof SwitchMaterial) { + + int colActive = d.containsKeyAndNotNull(TiC.EVENT_PROPERTY_ACTIVE_THUMB_COLOR) + ? TiConvert.toColor(d, TiC.EVENT_PROPERTY_ACTIVE_THUMB_COLOR) + : TiConvert.toColor(d, TiC.EVENT_PROPERTY_THUMB_COLOR); + int colNormal = d.containsKeyAndNotNull(TiC.EVENT_PROPERTY_THUMB_COLOR) + ? TiConvert.toColor(d, TiC.EVENT_PROPERTY_THUMB_COLOR) + : TiConvert.toColor(d, TiC.EVENT_PROPERTY_ACTIVE_THUMB_COLOR); + + ColorStateList trackStates = new ColorStateList( + new int[][] { + new int[] { -android.R.attr.state_enabled }, + new int[] { android.R.attr.state_checked }, + new int[] {} + }, + new int[] { + colNormal, + colActive, + colNormal + } + ); + ((SwitchMaterial) currentButton).setThumbTintList(trackStates); + } + } + if (d.containsKeyAndNotNull(TiC.PROPERTY_TINT_COLOR) || d.containsKeyAndNotNull(TiC.PROPERTY_ACTIVE_TINT_COLOR)) { CompoundButton currentButton = (CompoundButton) getNativeView(); diff --git a/android/titanium/src/java/org/appcelerator/titanium/TiC.java b/android/titanium/src/java/org/appcelerator/titanium/TiC.java index 58beebdde16..2cb05f66dd6 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/TiC.java +++ b/android/titanium/src/java/org/appcelerator/titanium/TiC.java @@ -142,6 +142,8 @@ public class TiC public static final String EVENT_PROPERTY_TAB = "tab"; public static final String EVENT_PROPERTY_THUMB_OFFSET = "thumbOffset"; public static final String EVENT_PROPERTY_THUMB_SIZE = "thumbSize"; + public static final String EVENT_PROPERTY_THUMB_COLOR = "thumbColor"; + public static final String EVENT_PROPERTY_ACTIVE_THUMB_COLOR = "activeThumbColor"; public static final String EVENT_PROPERTY_TYPE = "type"; public static final String EVENT_PROPERTY_VELOCITY = "velocity"; public static final String EVENT_PROPERTY_X = "x"; diff --git a/apidoc/Titanium/UI/Switch.yml b/apidoc/Titanium/UI/Switch.yml index 65135520449..7df9af141ad 100644 --- a/apidoc/Titanium/UI/Switch.yml +++ b/apidoc/Titanium/UI/Switch.yml @@ -138,6 +138,28 @@ properties: platforms: [android] since: {android: 12.4.0} + - name: activeThumbColor + summary: The color used to tint the thumb icon of the switch when it is turned on. + description: | + The color used to tint the thumb icon of the switch when it is turned on. + + Android: Active thumb color of the Material Switch. + type: [String, Titanium.UI.Color] + default: undefined + platforms: [android] + since: {android: 12.4.0} + + - name: thumbColor + summary: The color used to tint the thumb icon of the switch when it is turned off. + description: | + The color used to tint the thumb icon of the switch when it is turned off. + + Android: Inactive thumb color of the Material Switch. + type: [String, Titanium.UI.Color] + default: undefined + platforms: [android] + since: {android: 12.4.0} + - name: onTintColor summary: The color used to tint the appearance of the switch when it is turned on. type: [String, Titanium.UI.Color]