自定义弹窗中有弹出键盘的需要,但是弹出之后如何消除键盘和弹窗之间的距离

自定义弹窗中有弹出键盘的需要,但是弹出之后如何消除键盘和弹窗之间的距离 -鸿蒙开发者社区

类似红框区域,这个距离如何消除?

有的时候开发者不想要这种效果,这种之前想到了expandSafeArea来实现他这个诉求,但是实操写代码发现这种不能实现

HarmonyOS
2024-05-26 15:48:01
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
vclearner

使用的核心API

核心代码解释

@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、弹窗位置 
  } 
}

最后写代码发现可以在自定义弹窗的位置用offset这个通用属性就可以设置距离,实测这个距离是相对于弹窗来说的。

实现效果


分享
微博
QQ
微信
回复
2024-05-27 20:48:09
相关问题
如何自定义弹窗中再次弹窗
798浏览 • 1回复 待解决
自定义弹窗自定义转场动画
376浏览 • 1回复 待解决
自定义弹窗如何嵌套使用
399浏览 • 1回复 待解决
如何实现弹窗键盘避让
495浏览 • 1回复 待解决
如何判断软键盘是否弹出
627浏览 • 1回复 待解决
自定义弹窗使用相关问题
342浏览 • 1回复 待解决
如何设置自定义弹窗位置
648浏览 • 1回复 待解决
如何去除自定义弹窗白色背景
661浏览 • 1回复 待解决
自定义弹窗变量如何传递给页面
937浏览 • 1回复 待解决
关于软键盘弹出遮挡问题
346浏览 • 1回复 待解决
如何理解自定义弹窗gridCount参数
793浏览 • 1回复 待解决
自定义弹窗大小如何自适应内容
758浏览 • 1回复 待解决