Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): optionBar color properties #14066

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
hansemannn marked this conversation as resolved.
Show resolved Hide resolved
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
Loading