鸿蒙_自定义弹出框 (CustomDialog)

1.自定义弹出框 (CustomDialog) 

//1.新建文件CustomDialogExample

@CustomDialog

export struct CustomDialogExample {

  cancel: () => void = () => {

}

  confirm: () => void = () => {

}

  @Prop mess: string = '加载中1。。。'

  controller: CustomDialogController;

  build() {

    Column() {

      LoadingProgress().width(48)

        .height(48)

        .color(Color.White)

      Text(this.mess).fontSize(14)

        .fontColor(Color.White)

      Text('我是内容').fontSize(20).margin({ top: 10, bottom: 10 })

      Flex({ justifyContent: FlexAlign.SpaceAround }) {

        Button('cancel')

          .onClick(() => {

            this.controller.close();

            if (this.cancel) {

              this.cancel();

            }

          }).backgroundColor(0xffffff).fontColor(Color.Black)

        Button('confirm')

          .onClick(() => {

            this.controller.close();

            if (this.confirm) {

              this.confirm();

            }

          }).backgroundColor(0xffffff).fontColor(Color.Red)

      }.margin({ bottom: 2 })

    }

    .width(200)

    .height(200)

    .borderRadius(20)

    .backgroundColor(Color.Pink)

  }

}

//2.新建页面:CustomDialogUser

import { CustomDialogExample } from './CustomDialogExample';

@Entry

@ComponentV2

struct CustomDialogUser {

  dialogController: CustomDialogController = new CustomDialogController({

    builder: CustomDialogExample({

      cancel: ()=> { this.onCancel() },

      confirm: ()=> { this.onAccept() },

      mess:'加载中2。。。'

    }),

    alignment: DialogAlignment.Center,

    customStyle:true,

  });

  onCancel() {

    console.info('Callback when the first button is clicked');

  }

  onAccept() {

    console.info('Callback when the second button is clicked');

  }

  build() {

    Column() {

      Button('click me')

        .onClick(() => {

          this.dialogController.open();

        })

    }.width('100%').margin({ top: 50 })

  }

}


2参考官网链接:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-common-components-custom-dialog#%E5%BC%B9%E5%87%BA%E6%A1%86%E7%9A%84%E6%A0%B7%E5%BC%8F

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容