HarmonyOS TextArea如何在enterKeyType为send的情况下,点击发送不收起键盘?

如题:HarmonyOS TextArea如何在enterKeyType为send的情况下,点击发送不收起键盘?

阅读 561
1 个回答

建议先使用RichEditor来开发。RichEditor可以由开发者控制点击发送以后是否收起键盘。如下:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-richeditor-V5\#submitcallback12

使用RichEditor,参考demo:

@Entry
@Component
struct Index {
  controller: RichEditorController = new RichEditorController();
  options: RichEditorOptions = { controller: this.controller };

  build() {
    Row() {
      Column() {
        RichEditor(this.options)
          .onReady(() => {
            this.controller.addTextSpan("@地球 ",
              {
                style:
                {
                  fontColor: '#007dff',
                  fontSize: 16
                }
              })
          })
          .onIMEInputComplete((value: RichEditorTextSpanResult) => {
            console.log(`reulst ==> ${JSON.stringify(value)}`);
          })
          .enterKeyType(EnterKeyType.Send)
          .borderWidth(1)
          .borderColor(Color.White)
          .backgroundColor(Color.White)
          .width("100%")
          .onSubmit((enterKey: EnterKeyType, event: SubmitEvent) => {
            // 调用时保持编辑态。
            event.keepEditableState();
          })
      }
      .width("100%")
    }
    .height("100%")
    .backgroundColor('#ffeeeeee')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进