HarmonyOS中,使用CustomDialog如何设置宽度?

HarmonyOS中,使用CustomDialog如何设置宽度?

阅读 639
1 个回答

可以通过以下方式设置 CustomDialog 的宽度:
使用模态转场实现。示例代码:

@CustomDialog
struct CustomDialogExample {
  cancel: () => void = () => {
    console.info('Callback when the first button is clicked')
  }
  confirm: () => void = () => {
    console.info('Callback when the second button is clicked')
  }
  controller: CustomDialogController = new CustomDialogController({
    builder: CustomDialogExample({
      cancel: this.cancel,
      confirm: this.confirm,
    }),
    autoCancel: true,
    customStyle: true,

  })
  @State showFlag: Visibility = Visibility.Visible;

  build() {
    Column() {
      Text('我是内容')
      .fontSize(20)
      .margin({ top: 10, bottom: 10 })
      .backgroundColor('#FFFFFF')
      .height(200)
      .width('100%')
      .margin({ top: 600 })

    }
  .width('100%')
  .height('100%')
  .onClick(() => {
      this.showFlag = Visibility.Hidden
      setTimeout(() => {
        this.controller.close()
  }
  }
  }
  }

另外,通过 CustomDialogController(value: CustomDialogControllerOptions) ,Option 属性支持 customStyle、gridCount。customStyle 设为 false ,同时设置 gridCount 栅格数;customStyle 设为 true ,大小由子组件决定。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进