HarmonyOS CustomDialog和TextInput弹起后,键盘与Dialog中间有间距

使用调用CustomDialogController.open()后,Dialog出现TextInput自动focus,系统键盘拉起。但是Dialog和系统键盘之间出现了莫名间距。

HarmonyOS CustomDialog和TextInput弹起后,键盘与Dialog中间有间距 -鸿蒙开发者社区

HarmonyOS
2025-01-09 15:31:12
1153浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

弹窗位置调整可以将customStyle设置为true并且给弹窗内部的column布局设置偏移.offset({ x: 0, y: xx})。参考示例如下:

@Entry
@Component
struct KeyboadPage4 {
  @State content: string = 'CustomDialogPage';
  customDialogController: CustomDialogController = new CustomDialogController({
    builder: CustomEditDialogWidget({}),
    alignment: DialogAlignment.Bottom,
    maskColor: Color.Grey,
    customStyle: true
  });

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

@CustomDialog
export struct CustomEditDialogWidget {
  controller?: CustomDialogController;

  build() {
    Column() {
      Text(`请输入`).margin({ top: 20 })
      TextInput({ placeholder: `请输入` })
        .width("90%")
        .height('30%')
        .backgroundColor(Color.White)
        .borderWidth(1)
        .borderColor("#666")
        .borderRadius(10)
        .margin({ top: 20, bottom: 20 })
        .defaultFocus(true)
    }
    .width("80%")
    .borderRadius(15)
    .backgroundColor(Color.White)
    .borderWidth(1)
    .offset({ x: 0, 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.
分享
微博
QQ
微信
回复
2025-01-09 18:44:52
相关问题
HarmonyOS TextInput组件弹起键盘
588浏览 • 1回复 待解决
HarmonyOS 自定义弹框键盘有间距
1058浏览 • 1回复 待解决
HarmonyOS dialog键盘
704浏览 • 1回复 待解决
HarmonyOS 使用自定义相机左边有间距
821浏览 • 1回复 待解决
CustomDialog键盘的问题
1171浏览 • 1回复 待解决
怎么监听键盘弹起关闭事件?
3558浏览 • 1回复 待解决
HarmonyOS TextInput键盘相关问题咨询
1230浏览 • 1回复 待解决
HarmonyOS CustomDialog底部默认间距
1058浏览 • 1回复 待解决
HarmonyOS 键盘弹起,UI被压缩
885浏览 • 1回复 待解决
HarmonyOS 可否主动弹起键盘
540浏览 • 1回复 待解决
HarmonyOS 自定义键盘弹起遮住输入框
1514浏览 • 1回复 待解决
HarmonyOS Textinput如何实现中间插入
1071浏览 • 1回复 待解决