HarmonyOS RichEditor组件可以设置默认优先的键盘类型吗?比如默认优先为数字输入键盘 -

HarmonyOS
2024-12-26 14:24:03
784浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

RichEditor组件目前不支持直接设置系统键盘类型。

1.可以通过RichEditor组件的customKeyboard属性可以设置自定义键盘,进而控制系统键盘。

2.可以使用input配合其他组件来实现。代码如下:

// xxx.ets
@Entry
@Component
struct RichEditorExample {
  controller: RichEditorController = new RichEditorController()
  // 自定义键盘组件
  @Builder CustomKeyboardBuilder() {
    Column() {
      Grid() {
        ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item: number | string) => {
          GridItem() {
            Button(item + "")
              .width(110).onClick(() => {
              this.controller.addTextSpan(item + '', {
                offset: this.controller.getCaretOffset(),
                style:
                {
                  fontColor: Color.Orange,
                  fontSize: 30
                }
              })
              this.controller.setCaretOffset(this.controller.getCaretOffset() + item.toString().length)
            })
          }
        })
      }.maxCount(3).columnsGap(10).rowsGap(10).padding(5)
    }.backgroundColor(Color.Gray)
  }
  build() {
    Column() {
      RichEditor({ controller: this.controller })
        // 绑定自定义键盘
        .customKeyboard(this.CustomKeyboardBuilder()).margin(10).border({ width: 1 })
        .height(200)
        .borderWidth(1)
        .borderColor(Color.Red)
        .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.
分享
微博
QQ
微信
回复
2024-12-26 17:06:32
相关问题
HarmonyOS键盘会变为非数字输入
507浏览 • 1回复 待解决
设置Task优先方法
1356浏览 • 1回复 待解决
如何设置约束优先级,有人知道
1294浏览 • 2回复 待解决
Image组件如何设置默认图?
1811浏览 • 1回复 待解决
HarmonyOS 键盘输入不能输入负数
534浏览 • 1回复 待解决
求大佬告知如何设置Task优先
2426浏览 • 1回复 待解决
HarmonyOS textInput显示数字键盘
690浏览 • 1回复 待解决
HarmonyOS 数字自定义键盘如何实现
1309浏览 • 1回复 待解决