diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md index be30bb4222803d71b6ae98a8eecb1631c53e668a..db7024c5ff5defa0b621ab906782caac26038e61 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @@ -1,215 +1,238 @@ # 输入法框架 -> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +本模块提供对输入法框架的管理,包括隐藏输入法、查询已安装的输入法列表和拉起选择输入法弹窗。 +> **说明:** +> +> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 -``` +```js import inputMethod from '@ohos.inputmethod'; ``` -## inputMethod6+ +## 常量 常量值。 -**系统能力**:以下各项对应的系统能力均为SystemCapability.Miscservices.InputMethodFramework - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| MAX_TYPE_NUM | number | 是 | 否 | 可支持的最大输入法个数。 | +**系统能力:** SystemCapability.Miscservices.InputMethodFramework +| 名称 | 参数类型 | 常量值 | 说明 | +| -------- | -------- | ---------- | -------- | +| MAX_TYPE_NUM | number | 128 | 可支持的最大输入法个数。 | -## InputMethodProperty6+ +## InputMethodProperty 输入法应用属性。 -**系统能力**:以下各项对应的系统能力均为SystemCapability.Miscservices.InputMethodFramework +**系统能力:** SystemCapability.Miscservices.InputMethodFramework | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | -| packageName | string | 是 | 否 | 包名。 | -| methodId | string | 是 | 否 | Ability名。 | +| packageName | string | 是 | 否 | 输入法包名。 | +| methodId | string | 是 | 否 | 输入法唯一标识。 | ## inputMethod.getInputMethodController getInputMethodController(): InputMethodController -获取客户端实例[InputMethodController](#InputMethodController)。 +获取客户端实例[InputMethodController](#inputmethodcontroller)。 -**系统能力**:SystemCapability.Miscservices.InputMethodFramework +**系统能力:** SystemCapability.Miscservices.InputMethodFramework **返回值:** - | 类型 | 说明 | - | -------- | -------- | - | [InputMethodController](#InputMethodController) | 回调返回当前客户端实例。 | +| 类型 | 说明 | +| -------- | -------- | +| [InputMethodController](#inputmethodcontroller) | 返回当前客户端实例。 | **示例:** ```js - var InputMethodController = inputMethod.getInputMethodController(); +let inputMethodController = inputMethod.getInputMethodController(); ``` -## inputMethod.getInputMethodSetting6+ +## inputMethod.getInputMethodSetting getInputMethodSetting(): InputMethodSetting -获取客户端设置实例[InputMethodSetting](#InputMethodSetting)。 +获取客户端设置实例[InputMethodSetting](#inputmethodsetting)。 -**系统能力**: SystemCapability.Miscservices.InputMethodFramework +**系统能力:** SystemCapability.Miscservices.InputMethodFramework **返回值:** -| 类型 | 说明 | -| ----------------------------------------- | ---------------------------- | -| [InputMethodSetting](#InputMethodSetting) | 回调返回当前客户端设置实例。 | - +| 类型 | 说明 | +| ----------------------------------------- | ------------------------ | +| [InputMethodSetting](#inputmethodsetting) | 返回当前客户端设置实例。 | **示例:** - + ```js - var InputMethodSetting = inputMethod.getInputMethodSetting(); +let inputMethodSetting = inputMethod.getInputMethodSetting(); ``` ## InputMethodController -下列API示例中都需使用[getInputMethodController](#getInputMethodController)回调获取到InputMethodController实例,再通过此实例调用对应方法。 +下列API示例中都需使用[getInputMethodController](#inputmethodgetinputmethodcontroller)回调获取到InputMethodController实例,再通过此实例调用对应方法。 ### stopInput stopInput(callback: AsyncCallback<boolean>): void -隐藏输入法。 +结束输入法会话。使用callback异步回调。 -**系统能力**:SystemCapability.Miscservices.InputMethodFramework +**系统能力:** SystemCapability.Miscservices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| callback | AsyncCallback<boolean> | 是 | 返回输入法隐藏是否成功。 | +| callback | AsyncCallback<boolean> | 是 | 回调函数,返回结束输入法会话是否成功的结果。true表示结束输入法会话成功;false表示结束输入法会话失败。 | **示例:** ```js - InputMethodController.stopInput((error)=>{ - console.info('stopInput'); - }); +inputMethodController.stopInput((error, result) => { + if (error) { + console.error('Failed to stop inputmethod session: ' + JSON.stringify(error)); + return; + } + if (result) { + console.info('Succeeded in stopping inputmethod session.'); + } else { + console.error('Failed to stop inputmethod session.'); + } +}); ``` ### stopInput stopInput(): Promise<boolean> -隐藏输入法。 +结束输入法会话。使用Promise异步回调。 -**系统能力**: SystemCapability.Miscservices.InputMethodFramework +**系统能力:** SystemCapability.Miscservices.InputMethodFramework **返回值:** | 类型 | 说明 | | -------- | -------- | -| Promise<boolean> | 返回输入法隐藏是否成功。 | +| Promise<boolean> | Promise对象,返回结束输入法会话是否成功的结果。true表示结束输入法会话成功;false表示结束输入法会话失败。 | **示例:** - ```js - var isSuccess = InputMethodController.stopInput(); - console.info('stopInput isSuccess = ' + isSuccess); +inputMethodController.stopInput().then((result) => { + if (result) { + console.info('Succeeded in stopping inputmethod session.'); + } else { + console.error('Failed to stop inputmethod session'); + } +}) ``` -## InputMethodSetting6+ +## InputMethodSetting -下列API示例中都需使用[getInputMethodSetting](#getInputMethodSetting)回调获取到InputMethodSetting实例,再通过此实例调用对应方法。 +下列API示例中都需使用[getInputMethodSetting](#inputmethodgetinputmethodsetting)回调获取到InputMethodSetting实例,再通过此实例调用对应方法。 ### listInputMethod listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void -查询已安装的输入法列表。 +查询已安装的输入法列表。使用callback异步回调。 -**系统能力**: SystemCapability.Miscservices.InputMethodFramework +**系统能力:** SystemCapability.Miscservices.InputMethodFramework **参数:** + | 参数名 | 类型 | 必填 | 说明 | | -------- | -------------------------------------------------- | ---- | ---------------------- | -| callback | Array<[InputMethodProperty](#InputMethodProperty)> | 是 | 返回已安装输入法列表。 | +| callback | Array<[InputMethodProperty](#inputmethodproperty)> | 是 | 回调函数,返回已安装的输入法列表。 | **示例:** - + ```js - InputMethodSetting.listInputMethod((properties)=>{ - for (var i = 0;i < properties.length; i++) { - var property = properties[i]; - console.info(property.packageName + "/" + property.methodId); +inputMethodSetting.listInputMethod((err, data) => { + if(err) { + console.error('Failed to list inputmethods: ' + JSON.stringify(err)); + return; } - }); + console.log('Succeeded in listing inputmethods, data: ' + JSON.stringify(data)); + }); ``` ### listInputMethod listInputMethod(): Promise<Array<InputMethodProperty>> -查询已安装的输入法列表。 +查询已安装的输入法列表。使用Promise异步回调。 -**系统能力**: SystemCapability.Miscservices.InputMethodFramework +**系统能力:** SystemCapability.Miscservices.InputMethodFramework **返回值:** + | 类型 | 说明 | | ----------------------------------------------------------- | ---------------------- | -| Promise> | 返回已安装输入法列表。 | +| Promise> | Promise对象,返回已安装的输入法列表。| **示例:** - + ```js - var properties = InputMethodSetting.listInputMethod(); - for (var i = 0;i < properties.length; i++) { - var property = properties[i]; - console.info(property.packageName + "/" + property.methodId); - } +inputMethodSetting.listInputMethod().then((data) => { + console.info('Succeeded in listing inputMethod.'); +}).catch((err) => { + console.error('Failed to list inputMethod: ' + JSON.stringify(err)); +}) ``` ### displayOptionalInputMethod displayOptionalInputMethod(callback: AsyncCallback<void>): void -显示输入法选择对话框。 +显示选择输入法弹窗。使用callback异步回调。 -**系统能力**: SystemCapability.Miscservices.InputMethodFramework +**系统能力:** SystemCapability.Miscservices.InputMethodFramework **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| callback | AsyncCallback<void> | 是 | 回调函数。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当选择输入法弹窗显示成功。err为undefined,否则为错误对象。 | **示例:** ```js - InputMethodSetting.displayOptionalInputMethod(()=>{ - console.info('displayOptionalInputMethod is called'); - }); +inputMethodSetting.displayOptionalInputMethod((err) => { + if (err) { + console.error('Failed to display optionalInputMethod:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in displaying optionalInputMethod.'); +}); ``` ### displayOptionalInputMethod - displayOptionalInputMethod(): Promise<void> +displayOptionalInputMethod(): Promise<void> - 显示输入法选择对话框。 +显示选择输入法弹窗。使用Promise异步回调。 - **系统能力**: SystemCapability.Miscservices.InputMethodFramework +**系统能力:** SystemCapability.Miscservices.InputMethodFramework **返回值:** | 类型 | 说明 | | -------- | -------- | -| Promise<void> | 回调函数。 | +| Promise<void> | 无返回结果的Promise对象。 | **示例:** - + ```js - InputMethodSetting.displayOptionalInputMethod(); +inputMethodSetting.displayOptionalInputMethod().then(() => { + console.info('Succeeded in displaying optionalInputMethod.'); +}).catch((err) => { + console.error('Failed to display optionalInputMethod: ' + JSON.stringify(err)); +}) ``` \ No newline at end of file