HarmonyOS 输入框自动避让偏移值

现在输入框的自动避让键盘的功能避让的底部距离是否可以调整, 假设我现在有个输入框, 输入框下面有一排功能键, 现在的自动避让功能只会避让这个输入框, 我能否设置额外的偏移量, 使得避让的距离多一点, 把下面的一排功能键也显示出来?

HarmonyOS
2024-12-24 17:25:50
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

请参考以下demo,在输入框下面加入Blank(‘50’):

import { inputMethod } from '@kit.IMEKit'
import { window } from '@kit.ArkUI'
@CustomDialog struct CustomDialogExample {
  controller?: CustomDialogController
  @State @Watch('keyboardHeightChange') keyboardHeight: number = 0
  @State @Watch('keyboardHeightChange') realKeyboardHeight: number = 0
  @State offsetY: number = 0
  aboutToAppear(): void {
    window.getLastWindow(getContext(this), (err, window) => {
      window.on("keyboardHeightChange", (keyboardHeight) => {
        if (keyboardHeight !== 0) {
          this.keyboardHeight = px2vp(keyboardHeight)
        }
      });
    })
  }
  keyboardHeightChange() {
    if (this.keyboardHeight !== 0 && this.realKeyboardHeight !== 0) {
      this.offsetY = this.realKeyboardHeight - this.keyboardHeight
    }
  }
  build() {
    Column() {
      Text('content')
        .fontSize(20)
      TextArea()
        .width("100%") .height(100)
      Blank('50')
      // Text('content') .fontSize(20)
    } .width("100%")
    .offset({y: this.offsetY})
    .backgroundColor(Color.White)
    .borderRadius({topLeft: 32, topRight: 32})
    .onAreaChange((oldValue: Area, newValue: Area) => {
      if (Number(oldValue.globalPosition.y) > Number(newValue.globalPosition.y)) {
        this.realKeyboardHeight = Number(oldValue.globalPosition.y) - Number(newValue.globalPosition.y)
        console.log("")
      }
    })
  }
}
@Entry
@Component struct CustomDialogTest {
  @State message: string = 'Hello World';
  dialogController: CustomDialogController = new CustomDialogController({
    builder: CustomDialogExample(), alignment: DialogAlignment.Bottom, customStyle: true
  })

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('HelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: 'container', align: VerticalAlign.Center },
          middle: { anchor: 'container', align: HorizontalAlign.Center }
        })
        .onClick(() => {
          this.dialogController.open()
        })
    }.height('100%').width('100%')
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-24 19:51:00
相关问题
HarmonyOS 密码输入框
783浏览 • 1回复 待解决
HarmonyOS 输入框无法对齐
1128浏览 • 1回复 待解决
HarmonyOS 适配-输入框问题
812浏览 • 1回复 待解决
获取输入框输入的内容
458浏览 • 2回复 待解决
HarmonyOS 修改输入框焦点
735浏览 • 1回复 待解决
HarmonyOS 键盘遮挡输入框
709浏览 • 1回复 待解决
HarmonyOS 输入框只能输入字母和数字
1073浏览 • 1回复 待解决
HarmonyOS 输入框屏蔽系统键盘
631浏览 • 1回复 待解决
HarmonyOS 输入框不显示内容
972浏览 • 2回复 待解决
HarmonyOS webview输入框被遮挡
768浏览 • 1回复 待解决
HarmonyOS 监听输入框删除键
1250浏览 • 1回复 待解决
HarmonyOS textInput 如何清空输入框
911浏览 • 2回复 待解决
HarmonyOS 输入框光标移位监听
859浏览 • 1回复 待解决