HarmonyOS 自定义键盘需要监听系统事件,完成收回键盘操作

全局事件,基本收回键盘的操作都会用到。

HarmonyOS
2024-12-18 16:30:45
875浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280
@Entry
@Component
struct TextInputExample {
  controller: TextInputController = new TextInputController()
  @State inputValue: string = ""

  // 自定义键盘组件
  @Builder
  CustomKeyboardBuilder() {
    Column() {
      Button('x').onClick(() => {
        // 关闭自定义键盘
        this.controller.stopEditing()
      })
      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)
  }

  build() {
    Column() {
      Text('1221213213')
        .height('20%')
        .backgroundColor(Color.Green)
      TextArea()
        .height('20%')
        .backgroundColor(Color.Orange)
      TextInput({ controller: this.controller, text: this.inputValue })// 绑定自定义键盘
        .customKeyboard(this.CustomKeyboardBuilder()).margin(10).border({ width: 1 }).height('48vp')
      Column()
        .width('100%')
        .height('70%')
        .backgroundColor(Color.Grey)
    }.height('100%')
    .width('100%')
    .onClick(() => {
      this.controller.stopEditing()
    })
    .backgroundColor(Color.Pink)
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-18 19:22:26
相关问题
HarmonyOS 如何监听键盘弹出收回
1658浏览 • 1回复 待解决
HarmonyOS 自定义键盘
1014浏览 • 1回复 待解决
HarmonyOS TextInput自定义键盘
1291浏览 • 1回复 待解决
HarmonyOS 键盘事件监听问题
1489浏览 • 1回复 待解决
小程序示例自定义键盘
1069浏览 • 1回复 待解决
HarmonyOS TextInput自定义键盘问题
1553浏览 • 1回复 待解决
HarmonyOS 数字自定义键盘如何实现
1231浏览 • 1回复 待解决
HarmonyOS 键盘顶部添加自定义组件
946浏览 • 1回复 待解决
HarmonyOS TextInput绑定自定义键盘问题
1349浏览 • 1回复 待解决
基于自定义键盘设置光标位置
1357浏览 • 1回复 待解决
HarmonyOS 自定义键盘防录屏方案
755浏览 • 1回复 待解决