HarmonyOS如何监听输入法右上角关闭按键?

如题:HarmonyOS如何监听输入法右上角关闭按键?

阅读 712
1 个回答

获取输入法应用客户端实例InputMethodAbility,仅支持输入法应用调用。

demo如下:

import { inputMethod } from '@kit.IMEKit'
import { BusinessError } from '@kit.BasicServicesKit'

@Entry
@Component
struct InputTest {
  build() {
    Column() {
      TextInput()

      Button('11')
        .onClick(() => {
          try {
            let inputMethodController = inputMethod.getController();
            inputMethodController.stopInputSession().then((result) => {
              if (result) {
                console.info('Succeeded in stopping inputSession.');
              } else {
                console.error('Failed to stopInputSession.');
              }
            }).catch((err : BusinessError) => {
              console.error('Failed to stopInputSession: ' + JSON.stringify(err));
            })
          } catch(err) {
            console.error('Failed to stopInputSession: ' + JSON.stringify(err));
          }
        })
    }
  }
}

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V1/js-apis-inputmethodengine-0000001630306157-V1\#ZH-CN\_TOPIC\_0000001714587377\_\_inputmethodenginegetinputmethodability9

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进