Skip to content

Commit d2e96b6

Browse files
committed
fix(dialogs): android buttonInkColor and buttonTitleColor not working
1 parent 9b8f7d4 commit d2e96b6

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/dialogs/dialogs.android.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getColorStateList } from '@nativescript-community/ui-material-core/android/utils';
12
import { TextField } from '@nativescript-community/ui-material-textfield';
23
import {
34
ActionOptions,
@@ -61,8 +62,8 @@ function createAlertDialogBuilder(options?: DialogOptions & MDCAlertControlerOpt
6162
options.view instanceof View
6263
? options.view
6364
: Builder.createViewFromEntry({
64-
moduleName: options.view as string
65-
});
65+
moduleName: options.view as string
66+
});
6667

6768
view.cssClasses.add(CSSUtils.MODAL_ROOT_VIEW_CSS_CLASS);
6869
const modalRootViewCssClasses = CSSUtils.getSystemCssClasses();
@@ -127,19 +128,27 @@ function showDialog(dlg: androidx.appcompat.app.AlertDialog, options: DialogOpti
127128

128129
// let { color, backgroundColor } = getButtonColors();
129130

131+
132+
130133
if (options.buttonInkColor || options.buttonTitleColor) {
131-
const buttons: android.widget.Button[] = [];
132-
for (let i = 0; i < 3; i++) {
133-
const id = dlg
134-
.getContext()
135-
.getResources()
136-
.getIdentifier('android:id/button' + i, null, null);
137-
buttons[i] = dlg.findViewById(id) as android.widget.Button;
134+
dlg.create();
135+
const buttons: com.google.android.material.button.MaterialButton[] = [];
136+
for (let i = -1; i > -4; i--) {
137+
buttons.push(dlg.getButton(i) as com.google.android.material.button.MaterialButton);
138138
}
139139

140+
const nInkColor = options.buttonInkColor && getColorStateList(options.buttonInkColor.android);
141+
const nTitleColor = options.buttonTitleColor && getColorStateList(options.buttonTitleColor.android);
142+
140143
buttons.forEach((button) => {
141144
if (button) {
142-
button.setTextColor((options.buttonInkColor || options.buttonTitleColor).android);
145+
if (nInkColor) {
146+
button.setRippleColor(nInkColor);
147+
}
148+
if (nTitleColor) {
149+
button.setTextColor(nTitleColor);
150+
button.setIconTint(nTitleColor);
151+
}
143152
}
144153
});
145154
}
@@ -334,8 +343,8 @@ export function confirm(arg: any): Promise<boolean> {
334343
defaultOptions,
335344
!isDialogOptions(arg)
336345
? {
337-
message: arg + ''
338-
}
346+
message: arg + ''
347+
}
339348
: arg
340349
);
341350
const alert = createAlertDialogBuilder(options);

0 commit comments

Comments
 (0)