AWTK 在嵌入式平台使用内置的输入法,在移动设备上使用系统的原生输入法。在 AWTK-Android 和 AWTK-IOS 中,使用的是 SDL 封装之后的系统原生输入法。在 AWTK-HarmonyOS 中,要使用系统的原生输入法。需要实现 input_method 接口:

1. 启动输入法

编辑器得到焦点时,启动输入法。

调用 OH_InputMethodController_Attach 函数启动输入法,注意需要先设置输入法需要的回调函数。

static ret_t input_method_harmony_enable(input_method_t *input_method) {
    InputMethod_ErrorCode code = InputMethod_ErrorCode::IME_ERR_OK;
    input_method_harmony_t *im = (input_method_harmony_t *)input_method;
    return_value_if_fail(im != NULL, RET_BAD_PARAMS);
    auto options = OH_AttachOptions_Create(true);
    auto textEditorProxy = OH_TextEditorProxy_CreateAndInit();
    auto inputMethodProxy = &(im->inputMethodProxy);

    code = OH_InputMethodController_Attach(textEditorProxy, options, inputMethodProxy);
    if (code == InputMethod_ErrorCode::IME_ERR_OK) {
        log_debug("attach input method ok\n");
    } else {
        log_warn("attach input method failed\n");
    }

    im->options = options;
    im->textEditorProxy = textEditorProxy;

    return RET_OK;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.

2. 关闭输入法

编辑器失去焦点时,关闭输入法。

<