diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java index 729549b64ad..cc18e9b3e95 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java @@ -7,6 +7,7 @@ package ti.modules.titanium.ui.widget; import android.content.Context; +import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.view.View; import android.view.ViewGroup; @@ -207,6 +208,58 @@ private void addButton(String title, String accessibilityLabel, Drawable imageDr MaterialButton button = new MaterialButton(context, null, attributeId); button.setEnabled(isEnabled); button.setText(title); + if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_SELECTED_BACKGROUND_COLOR)) { + ColorStateList oldColors = button.getBackgroundTintList(); + int col = TiConvert.toColor((String) proxy.getProperty(TiC.PROPERTY_SELECTED_BACKGROUND_COLOR), context); + ColorStateList trackStates = new ColorStateList( + new int[][] { + new int[] { -android.R.attr.state_checked }, + new int[] { android.R.attr.state_checked }, + }, + new int[] { + oldColors.getColorForState(new int[] { -android.R.attr.state_checked }, R.attr.colorOnSurface), + col + } + ); + button.setBackgroundTintList(trackStates); + } + if (proxy.hasPropertyAndNotNull("selectedBorderColor")) { + ColorStateList oldColors = button.getStrokeColor(); + int col = TiConvert.toColor((String) proxy.getProperty("selectedBorderColor"), context); + ColorStateList trackStates = new ColorStateList( + new int[][] { + new int[] { -android.R.attr.state_checked }, + new int[] { android.R.attr.state_checked }, + }, + new int[] { + oldColors.getColorForState(new int[] { -android.R.attr.state_checked }, R.attr.colorOnSurface), + col + } + ); + button.setStrokeColor(trackStates); + } + if (proxy.hasPropertyAndNotNull("selectedTextColor") || proxy.hasPropertyAndNotNull(TiC.PROPERTY_COLOR)) { + int textCol = button.getCurrentHintTextColor(); + int selCol = button.getCurrentTextColor(); + + if (proxy.hasPropertyAndNotNull("selectedTextColor")) { + selCol = TiConvert.toColor((String) proxy.getProperty("selectedTextColor"), context); + } + if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_COLOR)) { + textCol = TiConvert.toColor((String) proxy.getProperty(TiC.PROPERTY_COLOR), context); + } + ColorStateList trackStates = new ColorStateList( + new int[][] { + new int[] { -android.R.attr.state_checked }, + new int[] { android.R.attr.state_checked }, + }, + new int[] { + textCol, + selCol, + } + ); + button.setTextColor(trackStates); + } if ((accessibilityLabel != null) && !accessibilityLabel.isEmpty()) { button.setContentDescription(accessibilityLabel); } diff --git a/apidoc/Titanium/UI/OptionBar.yml b/apidoc/Titanium/UI/OptionBar.yml index 9c6fc680bf1..f96bbe19130 100644 --- a/apidoc/Titanium/UI/OptionBar.yml +++ b/apidoc/Titanium/UI/OptionBar.yml @@ -60,6 +60,30 @@ properties: default: horizontal availability: creation + - name: selectedBackgroundColor + summary: Background color of the selected button + type: [String, Titanium.UI.Color] + platforms: [android] + since: { android: "12.4.0"} + + - name: selectedTextColor + summary: Text color of the selected button + type: [String, Titanium.UI.Color] + platforms: [android] + since: { android: "12.4.0"} + + - name: selectedBorderColor + summary: Border color of the selected button + type: [String, Titanium.UI.Color] + platforms: [android] + since: { android: "12.4.0"} + + - name: color + summary: Text color of the unselected button + type: [String, Titanium.UI.Color] + platforms: [android] + since: { android: "12.4.0"} + examples: - title: Text-Only Buttons example: |