HarmonyOS 对话框布局

如图所示写了一个对话框,键盘没有弹出的时候显示是正常的,键盘弹出的时候,布局和键盘之间有缝隙要怎么处理?

HarmonyOS 对话框布局 -鸿蒙开发者社区

HarmonyOS
2025-01-09 17:13:23
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

间隙不是虚拟按键的高度,该间隙是dialog的规格问题,软键盘拉起后弹框和软键盘距离16vp导致的。

示例参考如下:

@Entry
@Component
struct CustomDialogPage {
  @State message: string = 'CustomDialogPage';
  customDialogController: CustomDialogController = new CustomDialogController({
    builder: CustomEditDialogWidget({
      tipString: '姓名',
      inputType: InputType.Normal,
      textInputConString: (info: string) => {
        // this.content = info
      }
    }),
    alignment: DialogAlignment.Bottom,
    maskColor: Color.Red, //1、蒙层颜色
    customStyle: true //2.1、弹窗位置
  });

  build() {
    Row() {
      Column() {
        Button(this.message).onClick(() => {
          this.customDialogController.open();
        })
      }
      .width('100%')
    }
    .height('100%')
  }
}

@CustomDialog
@Component
export struct CustomEditDialogWidget {
  controller?: CustomDialogController;
  @State textInputString: string = ""
  tipString: string = ""
  textInputConString = (info: string) => {
  }
  inputType: InputType = InputType.Normal

  build() {
    Column() {
      Text(`请输入${this.tipString}`).margin({ top: 20 })
      TextInput({ placeholder: `请输入${this.tipString}` })
        .width("90%")
        .backgroundColor(Color.White)
        .borderWidth(1)
        .borderColor("#666")
        .borderRadius(10)
        .margin({ top: 20 })
        .defaultFocus(true)
        .onChange((value: string) => {
          this.textInputString = value
        })
        .type(this.inputType)

      Row() {
        Text("取消")
          .fontColor("#333")
          .onClick(() => {
            this.controller?.close()
          })
          .padding({
            left: 35,
            right: 35,
            top: 15,
            bottom: 15
          })
        Text("|").opacity(0.5).height("100%")
        Text("确定")
          .fontColor("#000")
          .onClick(() => {
            if (this.textInputString !== "") {
              this.textInputConString(this.textInputString)
            }
            this.controller?.close()
          })
          .padding({
            left: 35,
            right: 35,
            top: 15,
            bottom: 15
          })
      }
      .width("100%")
      .height(50)
      .justifyContent(FlexAlign.SpaceAround)
      .margin({ top: 10 })

    }
    .width("90%")
    .borderRadius(15)
    .backgroundColor(Color.White)
    .borderWidth(5)
    .offset({ x: 0, y: 20 }) //2.2、弹窗位置,y等于16的时候刚刚好
  }
}
  • 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.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
分享
微博
QQ
微信
回复
2025-01-09 18:50:22
相关问题
HarmonyOS 弹出对话框
697浏览 • 1回复 待解决
HarmonyOS 对话框弹出页面被遮挡
750浏览 • 1回复 待解决
HarmonyOS class中创建对话框不能显示
624浏览 • 1回复 待解决
HarmonyOS 页面跳转后对话框不消失
721浏览 • 1回复 待解决
HarmonyOS 自定义对话框的控制器
413浏览 • 1回复 待解决
如何封装一个自定义Dialog对话框
2788浏览 • 1回复 待解决