HarmonyOS 键盘弹起后,自定义弹框上移问题

在弹框中使用textinput控件,点击输入键盘弹起,弹框进行上移了,有什么方法禁止弹框移动吗?还有那个输入框样式怎么定义成方格的样式,需要展示6个

HarmonyOS
2024-12-18 16:25:02
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

设置安全区域.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]);

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-expand-safe-area-V5

全模态内的输入框上抬需要开发者自己做,可以通过这个接口获取到键盘的高度来避让

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-inputmethod-0000001774281542

关于类似验证码数字输入框,请参考以下代码示例:

//验证码输入框
interface codeOne {
  str: string,
  isBorder: boolean
}

@Entry
@Component
export struct TextInputCodeView {
  // 验证码
  @State code: string = ''
  // 验证码位数
  @Prop
  someArrayLength: number = 4
  someArray: number[] = []

  aboutToAppear(): void {
    this.someArray = Array.from({ length: this.someArrayLength })
  }

  build() {
    Stack() {
      Row() {
        ForEach(this.someArray, (item: number, index: number) => {
          //加间隙
          if (index != 0) {
            Blank()
          }
          //index + 1 :表示输入框的位置。
          //填写验证码
          if (this.code.length >= index + 1) {
            this.OneText({ str: this.code.substring(index, index + 1), isBorder: index + 1 === this.someArray.length })
          } else {
            //没有验证码
            this.OneText({
              str: '',
              isBorder: this.code.length + 1 === index + 1
            })
          }
        }, (item: number, index: number) => JSON.stringify(index + 1)) //键值标识
      }
      .width('100%')

      TextInput({ placeholder: "" })
        .width('100%')
        .height('100%')
        .maxLength(this.someArray.length)
        .caretColor(Color.Transparent)
        .fontColor(Color.Transparent)
        .borderColor(Color.Transparent)
        .backgroundColor(Color.Transparent)
        .onChange((value: string) => {
          this.code = value
        })
        .onSubmit(async () => {
          //回车事件
        })
    }
    .width('100%')
    .height(60)
  }

  //参数:验证码内容,是否显示边框
  @Builder
  OneText(item: codeOne) {
    //判断,是否选中当前的输入框,是否有内容 。是当前选中的,没有内容,显示 |
    Text(item.isBorder && !item.str ? '|' : item.str as string)
      .width(50)
      .height(50)
      .textAlign(TextAlign.Center)
      .fontSize(20)
      .fontColor(item.isBorder && !item.str ? '#ffdd4f46' : Color.Black)
      .backgroundColor('#f3f4f6')
      .borderRadius(8)

  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-18 17:35:34


相关问题
HarmonyOS 自定义框关闭页面上
704浏览 • 1回复 待解决
HarmonyOS 自定义键盘弹起遮住输入框
1438浏览 • 1回复 待解决
HarmonyOS 自定义框封装问题
779浏览 • 1回复 待解决
HarmonyOS 自定义框组件问题
1239浏览 • 1回复 待解决
HarmonyOS TextInput自定义键盘问题
1549浏览 • 1回复 待解决
HarmonyOS 自定义框遮罩透传问题
695浏览 • 1回复 待解决
HarmonyOS 自定义键盘
1005浏览 • 1回复 待解决
HarmonyOS TextInput绑定自定义键盘问题
1347浏览 • 1回复 待解决
HarmonyOS WebView使用自定义键盘问题
864浏览 • 1回复 待解决
HarmonyOS TextInput自定义键盘
1289浏览 • 1回复 待解决
HarmonyOS 自定义框不能全屏
883浏览 • 1回复 待解决
HarmonyOS web弹起键盘问题
763浏览 • 1回复 待解决
HarmonyOS 自定义键盘输入框焦点问题
925浏览 • 1回复 待解决
自定义框的状态获取
1560浏览 • 1回复 待解决
小程序示例自定义键盘
1064浏览 • 1回复 待解决