HarmonyOS 如何将弹出的键盘显示在底部控件之上?

我在TextInput输入数值时,弹出自定义的键盘,但键盘弹出的状态时,仍需要保持底部的builder固定在界面最下面,也就是键盘要在底部builder布局之上,如何实现呢?

阅读 454
1 个回答

自定义键盘设置一个.margin({bottom:xx})

参考demo:

import { window } from '@kit.ArkUI'

@Entry
@Component
struct Input {

  controller: TextInputController = new TextInputController()
  @State inputValue: string = ""
  @State height1:string|number = '80%'
  @State supportAvoidance:boolean = true;
  // 自定义键盘组件
  @Builder CustomKeyboardBuilder() {
    Column() {
      Row(){
        Button('x').onClick(() => {
          // 关闭自定义键盘
          this.controller.stopEditing()
        }).margin(10)
      }
      Grid() {
        ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item:number|string) => {
          GridItem() {
            Button(item + "")
              .width(110).onClick(() => {
              this.inputValue += item
            })
          }
        })
      }.maxCount(3).columnsGap(10).rowsGap(10).padding(5)
    }.backgroundColor(Color.Gray).margin({bottom:150})
  }
  build() {
    Column() {
      Text('组件1')
        .layoutWeight(1)
      TextInput({ controller: this.controller, text: this.inputValue })
        // 绑定自定义键盘
        .customKeyboard(this.CustomKeyboardBuilder()).margin(10).border({ width: 1 })

      Text('组件2')
        .height('10%')
        .margin({bottom:10})
    }
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进