HarmonyOS 自定义Toast显示,多了一个白色背景

使用promptAction.openCustomDialog自定义Toast,显示时多了一块白色背景,但是代码没有相关设置;请问如何去除白色背景?

示例代码:

import promptAction from '@ohos.promptAction'  
let customDialogId: number = 0  
@Builder  
function customDialogBuilder(text: string) {  
  Column() {  
    Text (text)  
      .fontSize (18)  
      .fontColor(Color.White)  
      .textAlign(TextAlign.Center)  
      .backgroundColor(Color.Transparent)  
      .maxLines(-1)  
      .constraintSize ({ maxWidth: '70%' })  
  }  
  .backgroundColor(Color.Red)  
  .justifyContent(FlexAlign.Center)  
  .padding({ top: 16, left: 20, bottom: 16, right: 20 })  
  .borderRadius(12)  
}  
@Entry  
@Component  
struct showTextToast {  
  build() {  
  }  
  showAlignmentToast(text : string, alignment:DialogAlignment) {  
    promptAction.openCustomDialog({  
      builder: customDialogBuilder.bind(this,text),  
      alignment: alignment,  
      maskColor: Color.Green,  
      backgroundColor: Color.Red,  
      width:'10%',  
      cornerRadius: 0  
    }).then((dialogId: number) => {  
      customDialogId = dialogId  
      this.autoClose(dialogId)  
    })  
  }  
  autoClose(dialogId: number){  
    let timeId = setTimeout(() => {  
      promptAction.closeCustomDialog(dialogId)  
      clearTimeout(timeId)  
    },1500);  
  }  
}@Entry  
@Component  
struct showTextToast {  
  build() {  
  }  
  showAlignmentToast(text : string, alignment:DialogAlignment) {  
    promptAction.openCustomDialog({  
      builder: customDialogBuilder.bind(this,text),  
      alignment: alignment,  
      maskColor: Color.Green,  
      backgroundColor: Color.Red,  
      cornerRadius: 0  
    }).then((dialogId: number) => {  
      customDialogId = dialogId  
      this.autoClose(dialogId)  
    })  
  }  
  autoClose(dialogId: number){  
    let timeId = setTimeout(() => {  
      promptAction.closeCustomDialog(dialogId)  
      clearTimeout(timeId)  
    },1500);  
  }  
}
  • 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.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
HarmonyOS
2024-10-18 09:52:19
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

当前promptAction.openCustomDialog的CustomDialogOptions里并没有customStyle属性来设置背景色,这边建议通过CustomDialogController类显示自定义弹窗,其中设置customStyle为true即可取消背景色。

自定义弹窗不支持放在普通函数里面,所以会导致无法调用,把showCustomOffsetToast方法里面的取出来直接调用在用showCustomOffsetToast方法的地方,然后自定义弹窗传参用@Link,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-methods-custom-dialog-box-V5#customdialogcontrolleroptions%E5%AF%B9%E8%B1%A1%E8%AF%B4%E6%98%8E

分享
微博
QQ
微信
回复
2024-10-18 18:23:49
相关问题
如何实现一个自定义样式的toast提示
2763浏览 • 1回复 待解决
如何去除自定义弹窗的白色背景
3006浏览 • 1回复 待解决
HarmonyOS 实现一个自定义分类列表
1181浏览 • 1回复 待解决
HarmonyOS 如何自定义toast
952浏览 • 1回复 待解决
HarmonyOS 如何自定义 toast 样式?
1031浏览 • 1回复 待解决
如何实现一个自定义询问框
1181浏览 • 1回复 待解决
HarmonyOS一个自定义的tabs冲突
955浏览 • 1回复 待解决
HarmonyOS 如何自定义toast组件
907浏览 • 1回复 待解决
HarmonyOS 如何实现自定义Toast
685浏览 • 1回复 待解决
HarmonyOS 如何弹出一个toast
691浏览 • 1回复 待解决
怎样实现一个自定义播放器?
1120浏览 • 1回复 待解决
使用自定义函数创建一个UI组
952浏览 • 1回复 待解决
实现一个自定义动画,出现丢帧问题
1048浏览 • 1回复 待解决