键盘遮挡问题,文本输入框如何才能自动抬起避让弹出的键盘

自定义的component写了个文本输入框,但键盘弹起后输入框无法避让,文档中窗口默认的避让类型是有键盘的或者用expandAreatype的API也无法避让,请问如何才能做到避让

HarmonyOS
2024-04-29 22:35:14
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
honda1999

请参考:

@Entry 
@Component 
struct Page_3058 { 
  @State message: string = 'Hello World'; 
  dialogController: CustomDialogController = new CustomDialogController({ 
    builder: CustomDialogExample(), 
  }) 
 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
          .onClick(() => { 
            this.dialogController.open() 
          }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
} 
 
@CustomDialog 
struct CustomDialogExample { 
  controller: CustomDialogController = new CustomDialogController({ 
    builder: CustomDialogExample({}), 
  }) 
 
  build() { 
    Column() { 
      TextInput({}) 
        .fontSize(20) 
        .margin({ top: 10, bottom: 10 }) 
        .expandSafeArea([SafeAreaType.KEYBOARD, SafeAreaType.SYSTEM])//.maxLength(this.maxLength) 
        .borderWidth(0.5) 
        .borderRadius(4)// .type(this.keyboardType == '1' ? InputType.Number : InputType.Normal) 
        .height(40) 
        .defaultFocus(true) 
        .margin({ top: 30, left: 16, right: 16 }) 
      // .caretPosition(this.presentInputContent ? this.presentInputContent.length : 0) 
      // .onChange ((value:String))=>{ 
      // this.currentInputText = value; 
      // }) 
    } 
 
  } 
}
分享
微博
QQ
微信
回复
2024-04-30 21:13:07
相关问题
如何控制软键盘弹出对页面的遮挡
998浏览 • 1回复 待解决
如何实现键盘避让机制
552浏览 • 1回复 待解决
js如何清空一个input 输入框内容
5850浏览 • 1回复 待解决
如何判断软键盘是否弹出
329浏览 • 1回复 待解决
鸿蒙软键盘弹出后,页面底部按钮
2346浏览 • 0回复 待解决