目前toast不支持自定义样式,可以考虑使用promptAction.openCustomDialog。(支持与页面解耦,支持自定义圆角、字体大小、颜色、背景等) demo如下:import { BusinessError } from '@ohos.base'; import { ComponentContent } from "@ohos.arkui.node"; class Params { text: string = "" constructor(text: string) { this.text = text; } } @Builder function buildText(params: Params) { Column() { Text(params.text).fontSize(50).fontWeight(FontWeight.Bold).margin({ bottom: 36 }) }.backgroundColor('#FFF0F0F0').borderRadius(25) } @Entry @Component struct CustomDialog { @State message: string = "弹窗弹窗" build() { Row() { Column() { Button("click me").onClick(() => { let uiContext = this.getUIContext(); let promptAction = uiContext.getPromptAction(); let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message)); try { promptAction.openCustomDialog(contentNode); } catch (error) { let message = (error as BusinessError).message; let code = (error as BusinessError).code; console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`); }; }) }.width('100%').height('100%') }.height('100%') } }参考:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-UIContext.md\#opencustomdialog12
目前toast不支持自定义样式,可以考虑使用promptAction.openCustomDialog。(支持与页面解耦,支持自定义圆角、字体大小、颜色、背景等) demo如下:
参考:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-UIContext.md\#opencustomdialog12