HarmonyOS 自定义弹窗中,点击输入框,弹起键盘,输入框被顶出屏幕了

HarmonyOS 自定义弹窗中,点击输入框,弹起键盘,输入框被顶出屏幕了。

HarmonyOS
2024-11-26 09:58:48
847浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

​自定义弹窗仅适用于简单提示场景,不能替代页面使用。由于弹窗存在完全避让输入法行为,即在软键盘弹出时,会自动向上抬起软键盘高度,因此如果弹窗高度过大时,可能会导致部分区域不可见。建议使用模态框实现。 参考文档:​https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-sheet-transition-V5

参考demo:

@Entry 
@Component 
struct Index { 
  @State message: string = 'CustomDialog中TextInput输入时,弹起键盘,整个弹窗内容被键盘挤上了。\n' + 
    '期望页面固定,与键盘无关。帮忙看下这个问题怎么解决'; 
  @State isShow:Boolean = false 
  @Builder 
  BuildTop() { 
    Row() { 
      Row() { 
        Image($r('app.media.dialog_ic_rank')) 
          .objectFit(ImageFit.Contain) 
          .height(23) 
          .margin({ left: 6 }) 
          .onClick(() => { 
          }) 
      } 
      .width($r('app.float.default_63')) 
 
      Text('设置') 
        .fontSize($r('app.float.font_size_17')) 
        .fontColor($r('app.color.col_101')) 
 
      Row() { 
        Button($r('app.string.set_finish')) 
          .fontSize($r('app.float.font_size_14')) 
          .backgroundColor($r('app.color.col_101')) 
          .width($r('app.float.default_63')) 
          .height(30) 
      } 
    } 
    .width('100%') 
    .justifyContent(FlexAlign.SpaceBetween) 
    .alignItems(VerticalAlign.Center) 
  } 
 
  @Builder 
  BuildTextEditor() { 
    Column() { 
      this.BuilderCommonTitle($r('app.string.set_text_editor')) 
 
      TextInput({ 
        text: '', 
        placeholder: $r('app.string.set_text_editor_placeholder') 
      }) 
        .caretColor($r('app.color.app_green'))//光标颜色 
        .caretStyle({ width: 2 })//光标风格,宽度 
        .borderRadius(10) 
        .height(50) 
        .textAlign(TextAlign.Center) 
        .fontSize($r('app.float.font_size_17')) 
        .fontColor($r('app.color.col_101')) 
        .backgroundColor('#F6F7F9') 
        .margin({ left: 7, top: 10, right: 9 }) 
        .onChange((value) => { 
          // this.text = value 
        }) 
    } 
    .width('100%') 
    .margin({ top: 17 }) 
    .alignItems(HorizontalAlign.Start) 
  } 
  @Builder 
  BuildSkin() { 
    Column() { 
      Text('皮肤列表区域') 
    } 
    .justifyContent(FlexAlign.Center) 
    .width('100%') 
    .height('40%') 
    .margin({ top: 20 }) 
    .backgroundColor(Color.Gray) 
  } 
 
  @Builder 
  BuilderBottomPlayMode() { 
    Column() { 
      this.BuilderCommonTitle($r('app.string.set_play_mode')) 
 
      Row() { 
        Button($r('app.string.set_play_mode_manual')) 
          .width(115) 
          .height(45) 
          .margin({ left: 10 }) 
          .fontColor($r('app.color.col_101')) 
          .fontSize($r('app.float.font_size_14')) 
          .borderRadius(10) 
          .backgroundColor($r('app.color.app_green')) 
          .onClick(() => { 
          }) 
 
        Button($r('app.string.set_play_mode_auto')) 
          .width(115) 
          .height(45) 
          .margin({ left: 12 }) 
          .fontSize($r('app.float.font_size_14')) 
          .fontColor($r('app.color.col_101')) 
          .borderRadius(10) 
          .backgroundColor($r('app.color.app_green')) 
          .onClick(() => { 
          }) 
      } 
      .margin({ top: 11 }) 
    } 
    .width('100%') 
    .margin({ top: 17 }) 
    .alignItems(HorizontalAlign.Start) 
  } 
 
  @Builder 
  BuilderCommonTitle(title: string | Resource) { 
    Text(title) 
      .fontColor($r('app.color.col_101')) 
      .fontSize($r('app.float.font_size_14')) 
  } 
 
  @Builder bindSheetModel() { 
    Column() { 
      this.BuildTop() 
      Divider() 
        .height(0.5) 
        .backgroundColor($r('app.color.col_f5')) 
        .margin({ top: 21, left: 4, right: 4 }) 
      this.BuildTextEditor() 
      this.BuildSkin() 
      this.BuilderBottomPlayMode() 
    } 
    .align(Alignment.End) 
    .width('100%') 
    .height('100%') 
    .padding({ left: $r('app.float.default_16'), right: $r('app.float.default_16'), top: 21, bottom: 80 }) 
    .backgroundColor(Color.White) 
    .borderRadius({ topLeft: $r('app.float.default_17'), topRight: $r('app.float.default_17') }) 
  } 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(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.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
已于2024-11-26 15:14:30修改
分享
微博
QQ
微信
回复
2024-11-26 15:13:55
相关问题
HarmonyOS 自定义键盘弹起后遮住输入框
1527浏览 • 1回复 待解决
HarmonyOS 自定义键盘不能顶起输入框
1271浏览 • 1回复 待解决
HarmonyOS 自定义键盘输入框焦点问题
988浏览 • 1回复 待解决
HarmonyOS web输入框键盘遮住
753浏览 • 1回复 待解决
HarmonyOS 键盘遮挡输入框
753浏览 • 1回复 待解决
HarmonyOS webview里的输入框键盘覆盖
728浏览 • 1回复 待解决
HarmonyOS webview输入框遮挡
808浏览 • 1回复 待解决
HarmonyOS 输入框屏蔽系统键盘
692浏览 • 1回复 待解决
HarmonyOS 如何控制输入框弹出键盘
1039浏览 • 1回复 待解决
HarmonyOS 密码输入框
809浏览 • 1回复 待解决
获取输入框输入的内容
526浏览 • 2回复 待解决