Skip to content

Commit

Permalink
feat(android): optionBar color properties (#14066)
Browse files Browse the repository at this point in the history
* feat(android): optionBar color properties

* remove unused states

* docs
  • Loading branch information
m1ga committed Jul 10, 2024
1 parent d1bbe8a commit d5cff3c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
24 changes: 24 additions & 0 deletions apidoc/Titanium/UI/OptionBar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down

0 comments on commit d5cff3c

Please sign in to comment.