HarmonyOS 如何设置背景透明度

希望提供可设置背景透明度的相关接口。

HarmonyOS
2024-12-24 17:50:06
682浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

目前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%')
  }
}
  • 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.

参考:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-UIContext.md#opencustomdialog12

分享
微博
QQ
微信
回复
2024-12-24 19:20:44


相关问题
SideBarContainer如何设置透明度
2985浏览 • 1回复 待解决
HarmonyOS 如何设置颜色透明度
1651浏览 • 1回复 待解决
HarmonyOS Image UI 如何设置图片透明度
717浏览 • 1回复 待解决
设置子窗口透明度未生效
2227浏览 • 1回复 待解决
HarmonyOS 有没有设置颜色透明度的方法
1547浏览 • 1回复 待解决
背景透明度问题解决方案
1740浏览 • 1回复 待解决
HarmonyOS color颜色怎么指定透明度
1689浏览 • 1回复 待解决
自定义颜色透明度如何实现?
991浏览 • 1回复 待解决
HarmonyOS 如何实现透明度的渐变效果
704浏览 • 1回复 待解决