当前位置:   article > 正文

【HarmonyOS NEXT】自定义键盘无法自动弹起_enablekeyboardonfocus

enablekeyboardonfocus

【关键字】

textinput / enableKeyboardOnFocus / 键盘弹起

【问题描述】

使用textinput的enableKeyboardOnFocus方法,实现键盘会自动弹起。

cke_392.png

【解决方案】

推荐示例代码如下:

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct TextInputExample {
  5. controller: TextInputController = new TextInputController()
  6. @State inputValue: string = ""
  7. // 自定义键盘组件
  8. @Builder CustomKeyboardBuilder() {
  9. Column() {
  10. Button('x').onClick(() => {
  11. // 关闭自定义键盘
  12. this.controller.stopEditing()
  13. })
  14. Grid() {
  15. ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item:number|string) => {
  16. GridItem() {
  17. Button(item + "")
  18. .width(110).onClick(() => {
  19. this.inputValue += item
  20. })
  21. }
  22. })
  23. }.maxCount(3).columnsGap(10).rowsGap(10).padding(5)
  24. }.backgroundColor(Color.Gray)
  25. }
  26. build() {
  27. Column() {
  28. TextInput({ controller: this.controller, text: this.inputValue })
  29. // 绑定自定义键盘
  30. .customKeyboard(this.CustomKeyboardBuilder()).margin(10).border({ width: 1 })
  31. .enableKeyboardOnFocus(true)
  32. .defaultFocus(true)
  33. }
  34. }
  35. }

参考文档:https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/changelogs/OpenHarmony_4.1.3.2/changelogs-default-focus.md

注意:请添加:.defaultFocus(true)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/887884
推荐阅读
相关标签
  

闽ICP备14008679号