AlertDialog.show与TextPickerDialog.show系统在暗黑模式下,设置背景色backgroundColor不生效
export class DialogUtil {
// 文本选择器
static textPickerDialogShow(datas: Array<string>, currentSelected: number,
callBack: (value: TextPickerResult) => void) {
TextPickerDialog.show({
range: datas,
selected: currentSelected,
canLoop: false,
backgroundColor:$r("app.color.dialog_background"),
disappearTextStyle: {
color: $r("app.color.999"),
font: { size: $r("app.float.text_size_16"), weight: FontWeight.Normal }
},
textStyle: {
color: $r("app.color.999"),
font: { size: $r("app.float.text_size_16"), weight: FontWeight.Normal }
},
selectedTextStyle: { color: Color.Black, font: { size: $r("app.float.text_size_16"), weight: 600 } },
onAccept: (value: TextPickerResult) => {
callBack(value)
},
})
}
static alertDialogShow(message: string, sureTitle: string = '确定', sureClick?: () => void, cancelTitle?: string,
cancelClick?: () => void,) {
AlertDialog.show(
{
title: '提示',
backgroundColor:$r("app.color.dialog_background"),
message: message,
autoCancel: false,
alignment: DialogAlignment.Center,
gridCount: 4,
buttonDirection: DialogButtonDirection.HORIZONTAL,
buttons: cancelTitle != undefined ? [
{
value: cancelTitle,
fontColor: $r("app.color.999"),
action: cancelClick != undefined ? cancelClick : () => {
}
},
{
value: sureTitle,
fontColor: $r("app.color.theme"),
action: sureClick != undefined ? sureClick : () => {
}
},
] : [
{
value: sureTitle,
fontColor: $r("app.color.theme"),
action: sureClick != undefined ? sureClick : () => {
}
},
],
}
)
}
}
可以参考以下代码:
设置深色模式不随系统改变。
参考链接:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-inner-application-applicationcontext-V5
深色模式的适配,参考文档:
https://developer.huawei.com/consumer/cn/doc/design-guides/dark-mode-0000001823255497