HarmonyOS 如何实现自定义键盘-车牌输入

在HarmonyOS开发中,要实现车牌输入(多个TextInput组件),应该采用哪种方案?

方案一:TextInput+customKeyboard。

方案二:@ohos.inputMethodEngine。 (输入法服务)

方案三:TextInput+自定义弹窗。

HarmonyOS
2024-12-26 15:00:16
886浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

这边建议这边可以使用customKeyboard属性让自定义键盘和输入框绑定。可以参考下面例子:

@Entry
@Component
struct CustomDialogUser {
  controller: TextInputController = new TextInputController()
  @State inputValue: string = ""
  //自定义数字键盘
  @Builder CustomKeyboardBuilder() {
    Grid() {
      ForEach([1, 2, 3,'删除', 4, 5, 6,'@', 7, 8, 9,'.', '*', 0, '返回','完成'], (item:number|string) => {
        GridItem() {
          Text(item + "")
            .backgroundColor('rgb(255, 255, 255)')
            .fontColor(Color.Black)
            .width(80)
            .height(50)
            .textAlign(TextAlign.Center)
            .borderRadius(4)
            .onClick(() => {
              if(item == '返回'){
               } else if (item == '完成'){
                this.controller.stopEditing()
              } else if (item == '删除'){
                this.inputValue = this.inputValue.slice(0,this.inputValue.length-2)
              } else {
                this.inputValue += item
              }
            })
        }
      })
    }
    .height(300)
    .columnsGap(5).rowsGap(10)
    .padding(5)
    .columnsTemplate('1fr 1fr 1fr 1fr')
    .rowsTemplate('1fr 1fr 1fr 1fr ')
  }
  build() {
    Column() {
      TextInput({ placeholder: '', controller: this.controller, text: this.inputValue })
        .customKeyboard(this.CustomKeyboardBuilder()).margin(10).border({ width: 1 }).height('48vp')
    }
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-26 17:03:19


相关问题
HarmonyOS 如何实现车牌输入组件
611浏览 • 1回复 待解决
HarmonyOS 自定义键盘不能顶起输入
1243浏览 • 1回复 待解决
HarmonyOS 数字自定义键盘如何实现
1293浏览 • 1回复 待解决
HarmonyOS 自定义键盘输入框焦点问题
959浏览 • 1回复 待解决
HarmonyOS 自定义键盘弹起后遮住输入
1497浏览 • 1回复 待解决
HarmonyOS 自定义键盘
1030浏览 • 1回复 待解决
HarmonyOS TextInput自定义键盘
1315浏览 • 1回复 待解决
小程序示例自定义键盘
1111浏览 • 1回复 待解决
HarmonyOS TextInput自定义键盘问题
1564浏览 • 1回复 待解决