HarmonyOS @CustomDialog如何铺满整个屏幕

HarmonyOS
2024-12-25 13:34:04
865浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

可以通过设置CustomDialogController以下三个属性达到预期效果:

customStyle: true,
offset: { dx: 0, dy: 0 },
alignment: DialogAlignment.Top
  • 1.
  • 2.
  • 3.

可参考以下示例:

import { MeasureText } from '@kit.ArkUI';
import measure from '@ohos.measure'
import { http } from '@kit.NetworkKit';

const BLOCK_DEFAULT_BORDER_WIDTH = 4;

@Entry
@Component
struct SliderIndex {
  @State loginState: string = '未登录'
  dialogControllerTwo: CustomDialogController | null = new CustomDialogController({
    builder: CustomDialogExampleTwo({ msg: this.loginState }),
    customStyle: true,
    offset: { dx: 0, dy: 0 },
    alignment: DialogAlignment.Top,

    // offset: { dx: 0, dy: -25 }
  })
  controller?: CustomDialogController

  onPageShow(): void {

  }

  login() {

    return '登录失败';
  }

  build() {
    Column() {
      Text('当前状态:' + this.loginState)
      Text('登录')
        .onClick(() => {

          let res = this.login()
          this.loginState = res
          console.log('denglu ===', res)
          if (res === '登录失败') {
            if (this.dialogControllerTwo) {
              this.dialogControllerTwo.open()
            }
          }
        })
    }
  }
}

@CustomDialog
struct CustomDialogExampleTwo {
  controllerTwo?: CustomDialogController
  @Prop msg: string = ''

  build() {
    Column() {
      Text(this.msg)
        .fontSize(30)
        .height(100)
      Button('点我关闭弹窗')
        .onClick(() => {
          if (this.controllerTwo != undefined) {
            this.controllerTwo.close()
          }
        })
        .margin(20)
    }
    .width('100%')
    .height('100%')
    .backgroundColor(Color.Orange)
  }
}
  • 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.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
分享
微博
QQ
微信
回复
2024-12-25 15:23:20
相关问题
HarmonyOS Text组件无法铺满屏幕
631浏览 • 1回复 待解决
HarmonyOS 如何实现公共的customdialog
449浏览 • 1回复 待解决
HarmonyOS使用CustomDialog如何设置宽度
1000浏览 • 1回复 待解决
HarmonyOS CustomDialog显示层级如何控制
598浏览 • 1回复 待解决
HarmonyOS CustomDialog相关
641浏览 • 1回复 待解决
如何控制CustomDialog显示层级
1293浏览 • 1回复 待解决
HarmonyOS CustomDialog焦点
441浏览 • 1回复 待解决
HarmonyOS CustomDialog显示
502浏览 • 1回复 待解决