From 825d5776214eade2f3ef297b2058adfd82267611 Mon Sep 17 00:00:00 2001 From: zh-m Date: Wed, 30 Nov 2016 15:01:03 +0200 Subject: [PATCH] Background of the buttons inside dialog can be modified through global style in CSS --- tns-core-modules/ui/dialogs/dialogs-common.ts | 12 ++++++++++++ tns-core-modules/ui/dialogs/dialogs.android.ts | 11 +++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/tns-core-modules/ui/dialogs/dialogs-common.ts b/tns-core-modules/ui/dialogs/dialogs-common.ts index ea01f1546..fbf106cbb 100644 --- a/tns-core-modules/ui/dialogs/dialogs-common.ts +++ b/tns-core-modules/ui/dialogs/dialogs-common.ts @@ -60,6 +60,18 @@ export function getButtonColor(): color.Color { return buttonColor; } +var buttonBackgroundColor: color.Color; +export function getButtonBackgroundColor(): color.Color { + if (!buttonBackgroundColor) { + var btn = new button.Button(); + applySelectors(btn); + buttonBackgroundColor = btn.backgroundColor; + btn.onUnloaded(); + } + + return buttonBackgroundColor; +} + var textFieldColor: color.Color; export function getTextFieldColor(): color.Color { if (!textFieldColor) { diff --git a/tns-core-modules/ui/dialogs/dialogs.android.ts b/tns-core-modules/ui/dialogs/dialogs.android.ts index 083d5c15a..619168bf6 100644 --- a/tns-core-modules/ui/dialogs/dialogs.android.ts +++ b/tns-core-modules/ui/dialogs/dialogs.android.ts @@ -41,15 +41,22 @@ function showDialog(builder: android.app.AlertDialog.Builder) { } let buttonColor = dialogsCommon.getButtonColor(); - if (buttonColor) { + let buttonBackgroundColor = dialogsCommon.getButtonBackgroundColor(); + if (buttonColor || buttonBackgroundColor) { let buttons : android.widget.Button[] = []; for (let i = 0; i < 3; i++) { let id = dlg.getContext().getResources().getIdentifier("android:id/button" + i, null, null); buttons[i] = dlg.findViewById(id); } + buttons.forEach(button => { if (button) { - button.setTextColor(buttonColor.android); + if (buttonColor) { + button.setTextColor(buttonColor.android); + } + if (buttonBackgroundColor) { + button.setBackgroundColor(buttonBackgroundColor.android); + } } }); }