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 : () => {
            }
          },
        ],
      }
    )
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
HarmonyOS
2025-01-09 16:04:27
419浏览
收藏 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');
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

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

参考链接:

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
微信
回复
2025-01-09 17:26:06


相关问题
AlertDialog没有找到设置背景色API
1139浏览 • 1回复 待解决
HarmonyOS 如何设置渐变背景色
2093浏览 • 1回复 待解决
如何设置窗口的背景色
2441浏览 • 1回复 待解决
如何设置WebView的背景色
1530浏览 • 1回复 待解决
Button组件如何设置渐变背景色
3578浏览 • 1回复 待解决
HarmonyOS Select组件的背景色如何设置
512浏览 • 1回复 待解决
HarmonyOS 关于开屏背景色
528浏览 • 1回复 待解决
HarmonyOS 弹窗自带背景色
443浏览 • 1回复 待解决
使用js引擎 设置dom背景色无效
1290浏览 • 0回复 待解决
JSUI按钮 toolbar的按背景色怎么去掉
5784浏览 • 1回复 待解决
HarmonyOS List组如何将背景色设置透明
446浏览 • 1回复 待解决