自定义弹窗(CustomDialog)可以配置显示在Window上还是当前view吗?

自定义弹窗(CustomDialog)可以配置显示在Window上还是当前view吗,可以支持一下动态刷新自定义弹框的参数吗?

HarmonyOS
2024-10-08 13:02:20
1.0w浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

可以通过Stack布局来模拟实现Dialog的效果,同时可通过状态变量动态刷新数据。参考代码如下:

DialogFirst.ets  
import { router } from '@kit.ArkUI';  
  
@Entry  
@Component  
struct DialogFirst {  
  @State textValue: string = '请阅读隐私协议'  
  // 显隐控制设置为不占用  
  @State visible: Visibility = Visibility.None  
  
  onPageShow() {  
    const params = router.getParams() as Record<string, string>; // 获取传递过来的参数对象  
    if (params) {  
      this.textValue = params.info as string; // 获取info属性的值  
    }  
  }  
  
  build() {  
    Stack() {  
      // 初始页面  
      Row() {  
        Column() {  
          Text('Hello World')  
            .fontSize(50)  
            .fontWeight(FontWeight.Bold)  
          Button('click')  
            .onClick(() => {  
              console.log("hit me!")  
              if (this.visible == Visibility.Visible) {  
                this.visible = Visibility.None  
              } else {  
                this.visible = Visibility.Visible  
              }  
            })  
            .backgroundColor(0x777474)  
            .fontColor(0x000000)  
        }  
        .width('100%')  
      }  
      .height('100%')  
      .backgroundColor(0x885555)  
  
      //加了一个半透明灰色的蒙层效果  
      Text('')  
        .onClick(() => {  
          if (this.visible == Visibility.Visible) {  
            this.visible = Visibility.None  
          } else {  
            this.visible = Visibility.Visible  
          }  
        })  
        .width('100%')  
        .height('100%')  
        .opacity(0.16)  
        .backgroundColor(0x000000)  
        .visibility(this.visible)
  • 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.
分享
微博
QQ
微信
回复
2024-10-08 16:56:40


相关问题
HarmonyOS 自定义弹窗CustomDialog
486浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog问题
1041浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog 问题
468浏览 • 1回复 待解决
HarmonyOS 自定义弹窗 (CustomDialog)问题
986浏览 • 1回复 待解决
CustomDialog自定义动画
1016浏览 • 1回复 待解决
HarmonyOS 自定义弹窗不能显示问题
540浏览 • 1回复 待解决
HarmonyOS 自定义弹窗封装后不显示
894浏览 • 1回复 待解决