HarmonyOS 使用CustomDialogController的输入框在键盘弹出后有一个间隙

项目中使用CustomDialogController写了一个评论输入框,设置了alignment: DialogAlignment.Bottom,在弹出键盘后输入框和键盘中间有一定的间距,试过使用offset调整也没有效果。

HarmonyOS
2024-09-30 10:43:52
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

可以参考这个demo,修改最后一行offset(x,y)中y的参数控制弹窗上下移动:

@Entry  
@Component  
struct CustomDialogPage {  
  @State message: string = 'CustomDialogPage';  
  customDialogController: CustomDialogController = new CustomDialogController({  
    builder: CustomEditDialogWidget({  
      tipString: '姓名',  
      inputType: InputType.Normal,  
      textInputConString: (info: string) => {  
      }  
    }),  
    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.

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

分享
微博
QQ
微信
回复
2024-09-30 18:21:06
相关问题
HarmonyOS 如何控制输入框弹出键盘
972浏览 • 1回复 待解决
js如何清空一个input 输入框内容
8672浏览 • 2回复 待解决
HarmonyOS 键盘遮挡输入框
711浏览 • 1回复 待解决
HarmonyOS 输入框屏蔽系统键盘
635浏览 • 1回复 待解决
HarmonyOS 输入框获取焦点后无法弹出
762浏览 • 1回复 待解决
HarmonyOS web中输入框键盘遮住
721浏览 • 1回复 待解决
HarmonyOS webview里输入框键盘覆盖
697浏览 • 1回复 待解决
HarmonyOS 如何弹出一个toast
691浏览 • 1回复 待解决