HarmonyOS AlertDialog.show与TextPickerDialog.show系统在暗黑模式下,设置背景色不生效

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 : () => {
            }
          },
        ],
      }
    )
  }
}
HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

可以参考以下代码:

onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
  let applicationContext = this.context.getApplicationContext();
  applicationContext.setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK);
  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}

设置深色模式不随系统改变。

参考链接:

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

分享
微博
QQ
微信
回复
2天前
相关问题
AlertDialog没有找到设置背景色API
625浏览 • 1回复 待解决
HarmonyOS 如何设置渐变背景色
1248浏览 • 1回复 待解决
如何设置WebView的背景色
749浏览 • 1回复 待解决
如何设置窗口的背景色
2033浏览 • 1回复 待解决
Button组件如何设置渐变背景色
2809浏览 • 1回复 待解决
HarmonyOS Select组件的背景色如何设置
156浏览 • 1回复 待解决
使用js引擎 设置dom背景色无效
974浏览 • 0回复 待解决
HarmonyOS 关于开屏背景色
142浏览 • 1回复 待解决
HarmonyOS 弹窗自带背景色
153浏览 • 1回复 待解决
show databases显示问题
4763浏览 • 2回复 待解决
JSUI按钮 toolbar的按背景色怎么去掉
5472浏览 • 1回复 待解决