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 : () => {
            }
          },
        ],
      }
    )
  }
}
阅读 613
1 个回答

可以参考以下代码:

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进