js-apis-inputmethod.md 30.5 KB
Newer Older
Z
zhouyongfei 已提交
1 2
# 输入法框架

T
explain  
tianyu 已提交
3 4
本模块提供对输入法框架的管理,包括隐藏输入法、查询已安装的输入法列表和显示输入法选择对话框。

5
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
6
>
Z
zhouyongfei 已提交
7 8 9 10 11 12
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。


## 导入模块

```
13
import inputMethod from '@ohos.inputmethod';
Z
zhouyongfei 已提交
14 15 16 17 18 19
```

## inputMethod<sup>8+</sup>

常量值。

20
**系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework
Z
刷新  
zhouyongfei 已提交
21

Z
zhouyongfei 已提交
22 23
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
刷新  
zhouyongfei 已提交
24
| MAX_TYPE_NUM | number | 是 | 否 | 可支持的最大输入法个数。 |
Z
zhouyongfei 已提交
25 26


27
## InputMethodProperty<sup>8+</sup>
Z
zhouyongfei 已提交
28 29 30

输入法应用属性。

31
**系统能力**:以下各项对应的系统能力均为SystemCapability.MiscServices.InputMethodFramework
Z
刷新  
zhouyongfei 已提交
32

Z
zhouyongfei 已提交
33 34
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
35 36 37 38
| packageName<sup>deprecated</sup> | string | 是 | 否 | 包名。 |
| methodId<sup>deprecated</sup> | string | 是 | 否 | Ability名。 |
| name<sup>9+</sup>  | string | 是 | 否 | 包名。 |
| id<sup>9+</sup>    | string | 是 | 否 | Ability名。 |
Z
zhouyongfei 已提交
39

40
## inputMethod.getInputMethodController<sup>deprecated</sup>
Z
zhouyongfei 已提交
41 42 43

getInputMethodController(): InputMethodController

44
获取客户端实例[InputMethodController](#inputmethodcontroller)
Z
zhouyongfei 已提交
45

46 47 48 49 50
> **说明:** 
> 从API version 9开始废弃, 建议使用[getController](#getController)替代
>
> 从 API version 6开始支持。

51
**系统能力**:SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
52

53
**返回值:**
Z
zhouyongfei 已提交
54

55 56 57
| 类型                                            | 说明                     |
| ----------------------------------------------- | ------------------------ |
| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 |
Z
zhouyongfei 已提交
58

59
**示例:**
T
explain  
tianyu 已提交
60

61
```js
Z
zhouyongfei 已提交
62
  var InputMethodController = inputMethod.getInputMethodController();
63
```
64

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
## inputMethod.getController<sup>9+</sup>

getController(): InputMethodController

获取客户端实例[InputMethodController](#inputmethodcontroller)

**系统能力**:SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型                                            | 说明                     |
| ----------------------------------------------- | ------------------------ |
| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 |

**示例:**

```js
  var InputMethodController = inputMethod.getController();
```

85
## inputMethod.getInputMethodSetting<sup>8+</sup>
Z
zhouyongfei 已提交
86 87 88

getInputMethodSetting(): InputMethodSetting

89
获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)
Z
zhouyongfei 已提交
90

91
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
92

93
**返回值:**
Z
zhouyongfei 已提交
94

T
explain  
tianyu 已提交
95 96
| 类型                                      | 说明                         |
| ----------------------------------------- | ---------------------------- |
97
| [InputMethodSetting](#inputmethodsetting8) | 回调返回当前客户端设置实例。 |
Z
zhouyongfei 已提交
98 99


100
**示例:**
101 102

```js
Z
zhouyongfei 已提交
103
  var InputMethodSetting = inputMethod.getInputMethodSetting();
104
```
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

## inputMethod.getSetting<sup>9+</sup>

getSetting(): InputMethodSetting

获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型                                      | 说明                         |
| ----------------------------------------- | ---------------------------- |
| [InputMethodSetting](#inputmethodsetting8) | 回调返回当前客户端设置实例。 |


**示例:**

```js
  var InputMethodSetting = inputMethod.getSetting();
```

G
gaoxiang 已提交
127
## inputMethod.switchInputMethod<sup>9+</sup>
Z
zhouyongfei 已提交
128

Z
zhaolinglan 已提交
129
switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolean&gt;): void
G
gaoxiang 已提交
130

131
切换输入法。此接口仅可在Stage模型下使用。使用callback形式返回结果。参数个数为2,否则抛出异常。
132

133 134
**需要权限**: ohos.permission.CONNECT_IME_ABILITY

Z
zhaolinglan 已提交
135
**系统能力**:SystemCapability.MiscServices.InputMethodFramework
G
gaoxiang 已提交
136 137 138 139 140

**参数:**

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
G
gaoxiang 已提交
141
  |target | [InputmethodProperty](#inputmethodproperty8) | 是 | 传入要切换的目标输入法。 |
G
gaoxiang 已提交
142 143 144 145 146 147
  | callback | AsyncCallback&lt;boolean&gt; | 是 | 返回输入法切换是否成功。 |


**示例:**

```js
Z
zhaolinglan 已提交
148
inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'} ,(err,result) => {
Z
zhaolinglan 已提交
149
    if (err) {
Z
zhaolinglan 已提交
150
        console.error('switchInputMethod err: ' + JSON.stringify(err));
151 152
        return;
    }
Z
zhaolinglan 已提交
153
    if (result) {
Z
zhaolinglan 已提交
154
        console.info('Success to switchInputMethod.(callback)');
Z
zhaolinglan 已提交
155
    } else {
Z
zhaolinglan 已提交
156
        console.error('Failed to switchInputMethod.(callback)');
Z
zhaolinglan 已提交
157
    }
158
});
G
gaoxiang 已提交
159
```
G
gaoxiang 已提交
160
## inputMethod.switchInputMethod<sup>9+</sup>
Z
zhaolinglan 已提交
161
switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
G
gaoxiang 已提交
162

163
切换输入法。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。
G
gaoxiang 已提交
164

165 166
**需要权限**: ohos.permission.CONNECT_IME_ABILITY

Z
zhaolinglan 已提交
167
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
G
gaoxiang 已提交
168

G
gaoxiang 已提交
169
**参数:**
G
gaoxiang 已提交
170 171 172

  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
G
gaoxiang 已提交
173
  |target |  [InputmethodProperty](#inputmethodproperty8)| 是 | 传入要切换的目标输入法。 |
G
gaoxiang 已提交
174

G
gaoxiang 已提交
175
**返回值:**
B
bmeangel 已提交
176

G
gaoxiang 已提交
177 178
  | 类型                                      | 说明                         |
  | ----------------------------------------- | ---------------------------- |
179
  | Promise\<boolean> | 回调返回切换后的输入法。 |
G
gaoxiang 已提交
180

G
gaoxiang 已提交
181 182 183
**示例:**

```js
Z
zhaolinglan 已提交
184
inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard'}).then((result) => {
Z
zhaolinglan 已提交
185
    if (result) {
Z
zhaolinglan 已提交
186
        console.info('Success to switchInputMethod.(promise)');
Z
zhaolinglan 已提交
187
    } else {
Z
zhaolinglan 已提交
188
        console.error('Failed to switchInputMethod.(promise)');
Z
zhaolinglan 已提交
189 190
    }
}).catch((err) => {
Z
zhaolinglan 已提交
191
    console.error('switchInputMethod promise err: ' + err);
Z
zhaolinglan 已提交
192
})
G
gaoxiang 已提交
193
```
194

Z
zhaolinglan 已提交
195 196 197 198
## inputMethod.getCurrentInputMethod<sup>9+</sup>

getCurrentInputMethod(): InputMethodProperty

Z
zhaolinglan 已提交
199
获取当前输入法扩展应用,提供同步接口,返回当前输入法属性对象。
Z
zhaolinglan 已提交
200 201 202 203 204

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**返回值:**

Z
zhaolinglan 已提交
205 206 207
| 类型                                         | 说明                     |
| -------------------------------------------- | ------------------------ |
| [InputmethodProperty](#inputmethodproperty8) | 返回当前输入法属性对象。 |
Z
zhaolinglan 已提交
208 209 210 211 212 213 214

**示例:**

```js
var currentIme = inputMethod.getCurrentInputMethod();
```

215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>

switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback<boolean>): void

选择当前的输入法子类型。

**需要权限**: ohos.permission.CONNECT_IME_ABILITY

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
|target |  [InputMethodSubtype](#InputMethodSubtype)| 是 | 传入要切换的目标输入法子类型。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 返回输入法子类型切换是否成功。 |

**示例:**

```js
inputMethod.switchCurrentInputMethodSubtype(subType ,(err,result) => {
    if (err) {
        console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err));
        return;
    }
    if (result) {
        console.info('Success to switchCurrentInputMethodSubtype.(callback)');
    } else {
        console.error('Failed to switchCurrentInputMethodSubtype.(callback)');
    }
});
```

## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>

switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise&lt;boolean&gt;

切换输入法子类型。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。

**需要权限**: ohos.permission.CONNECT_IME_ABILITY

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
|target |  [InputMethodSubtype](#InputMethodSubtype)| 是 | 传入要切换的目标输入法子类型。 |

**示例:**

```js
inputMethod.switchCurrentInputMethodSubtype(subType).then((result) => {
    if (result) {
        console.info('Success to switchCurrentInputMethodSubtype.(promise)');
    } else {
        console.error('Failed to switchCurrentInputMethodSubtype.(promise)');
    }
}).catch((err) => {
    console.error('switchCurrentInputMethodSubtype promise err: ' + err);
})
```

## inputMethod.getCurrentInputMethodSubtype<sup>9+</sup>

getCurrentInputMethodSubtype(): InputMethodSubtype

获取当前输入法子类型。

**需要权限**: ohos.permission.CONNECT_IME_ABILITY

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型                                         | 说明                     |
| -------------------------------------------- | ------------------------ |
| [InputMethodSubtype](#InputMethodSubtype) | 返回当前输入法子类型对象。 |

**示例:**

```js
var currentImeSubType = inputMethod.getCurrentInputMethodSubtype();
```

## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>

switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback<boolean>): void

选择输入法和子类型。

**需要权限**: ohos.permission.CONNECT_IME_ABILITY

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
|inputMethodProperty |  [InputMethodProperty](#InputMethodProperty)| 是 | 传入要切换的目标输入法。 |
|inputMethodSubtype |  [inputMethodSubtype](#InputMethodSubtype)| 是 | 传入要切换的目标输入法子类型。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 返回输入法和子类型切换是否成功。 |

**示例:**

```js
inputMethod.switchCurrentInputMethodAndSubtype(property, subType ,(err,result) => {
    if (err) {
        console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err));
        return;
    }
    if (result) {
        console.info('Success to switchCurrentInputMethodAndSubtype.(callback)');
    } else {
        console.error('Failed to switchCurrentInputMethodAndSubtype.(callback)');
    }
});
```

## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>

switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, ): Promise&lt;boolean&gt;

切换输入法子类型。此接口仅可在Stage模型下使用。使用promise形式返回结果。参数个数为1,否则抛出异常。

**需要权限**: ohos.permission.CONNECT_IME_ABILITY

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
|inputMethodProperty |  [InputMethodProperty](#InputMethodProperty)| 是 | 传入要切换的目标输入法。 |
|inputMethodSubtype |  [inputMethodSubtype](#InputMethodSubtype)| 是 | 传入要切换的目标输入法子类型。 |

**示例:**

```js
inputMethod.switchCurrentInputMethodAndSubtype(property, subType).then((result) => {
    if (result) {
        console.info('Success to switchCurrentInputMethodAndSubtype.(promise)');
    } else {
        console.error('Failed to switchCurrentInputMethodAndSubtype.(promise)');
    }
}).catch((err) => {
    console.error('switchCurrentInputMethodAndSubtype promise err: ' + err);
})
```

365
## InputMethodController
Z
zhouyongfei 已提交
366

367
下列API示例中都需使用[getInputMethodController](#inputmethodgetinputmethodcontroller)回调获取到InputMethodController实例,再通过此实例调用对应方法。
Z
zhouyongfei 已提交
368

369
### stopInput<sup>deprecated</sup>
Z
zhouyongfei 已提交
370 371 372

stopInput(callback: AsyncCallback&lt;boolean&gt;): void

373
隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。
Z
zhouyongfei 已提交
374

375
**系统能力**:SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
376

377
**参数:**
Z
zhouyongfei 已提交
378

T
explain  
tianyu 已提交
379 380 381
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 返回输入法隐藏是否成功。 |
Z
zhouyongfei 已提交
382

383
**示例:**
Z
zhouyongfei 已提交
384

385
```js
Z
zhaolinglan 已提交
386
InputMethodController.stopInput((error, result) => {
Z
zhaolinglan 已提交
387
    if (error) {
Z
zhaolinglan 已提交
388
        console.error('failed to stopInput because: ' + JSON.stringify(error));
389 390
        return;
    }
Z
zhaolinglan 已提交
391
    if (result) {
Z
zhaolinglan 已提交
392
        console.info('Success to stopInput.(callback)');
Z
zhaolinglan 已提交
393
    } else {
Z
zhaolinglan 已提交
394
        console.error('Failed to stopInput.(callback)');
Z
zhaolinglan 已提交
395
    }
396
});
Z
zhouyongfei 已提交
397 398
```

399
### stopInput<sup>deprecated</sup>
Z
zhouyongfei 已提交
400 401 402

stopInput(): Promise&lt;boolean&gt;

403
隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常。
Z
zhouyongfei 已提交
404

405
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
406

407
**返回值:**
Z
zhouyongfei 已提交
408

T
explain  
tianyu 已提交
409 410 411
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | 返回输入法隐藏是否成功。 |
Z
zhouyongfei 已提交
412

413
**示例:**
Z
zhouyongfei 已提交
414 415


416
```js
Z
zhaolinglan 已提交
417 418
InputMethodController.stopInput().then((result) => {
    if (result) {
Z
zhaolinglan 已提交
419
        console.info('Success to stopInput.(promise)');
Z
zhaolinglan 已提交
420
    } else {
Z
zhaolinglan 已提交
421
        console.error('Failed to stopInput.(promise)');
Z
zhaolinglan 已提交
422 423
    }
}).catch((err) => {
Z
zhaolinglan 已提交
424
    console.error('stopInput promise err: ' + err);
Z
zhaolinglan 已提交
425
})
Z
zhouyongfei 已提交
426 427
```

428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
### stopInputSession<sup>9+</sup>

stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void

隐藏输入法。使用callback形式返回结果。参数个数为1,否则抛出异常。

**系统能力**:SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 返回输入法隐藏是否成功。 |

**示例:**

```js
InputMethodController.stopInputSession((error, result) => {
    if (error) {
        console.error('failed to stopInputSession because: ' + JSON.stringify(error));
        return;
    }
    if (result) {
        console.info('Success to stopInputSession.(callback)');
    } else {
        console.error('Failed to stopInputSession.(callback)');
    }
});
```

### stopInputSession

stopInputSession(): Promise&lt;boolean&gt;

隐藏输入法。使用promise形式返回结果。参数个数为0,否则抛出异常。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | 返回输入法隐藏是否成功。 |

**示例:**


```js
InputMethodController.stopInputSession().then((result) => {
    if (result) {
        console.info('Success to stopInputSession.(promise)');
    } else {
        console.error('Failed to stopInputSession.(promise)');
    }
}).catch((err) => {
    console.error('stopInputSession promise err: ' + err);
})
```

Z
zhaolinglan 已提交
487
### showSoftKeyboard<sup>9+</sup> ###
Z
zhaolinglan 已提交
488

Z
zhaolinglan 已提交
489
showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
Z
zhaolinglan 已提交
490

491
显示软键盘,使用callback异步回调。参数个数为1,否则抛出异常。
Z
zhaolinglan 已提交
492

Z
zhaolinglan 已提交
493
**系统能力:**  SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
494 495 496

**参数:**

Z
zhaolinglan 已提交
497
| 参数名   | 参数类型                  | 必填 | 说明       |
Z
zhaolinglan 已提交
498 499
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。 |
Z
zhaolinglan 已提交
500 501 502 503

**示例:**

```js
Z
zhaolinglan 已提交
504
InputMethodController.showSoftKeyboard((err) => {
Z
zhaolinglan 已提交
505
    if (err === undefined) {
Z
zhaolinglan 已提交
506
        console.info('showSoftKeyboard success');
Z
zhaolinglan 已提交
507
    } else {
Z
zhaolinglan 已提交
508
        console.error('showSoftKeyboard failed because : ' + JSON.stringify(err));
Z
zhaolinglan 已提交
509 510 511 512
    }
})
```

Z
zhaolinglan 已提交
513

Z
zhaolinglan 已提交
514
### showSoftKeyboard<sup>9+</sup> ###
Z
zhaolinglan 已提交
515

Z
zhaolinglan 已提交
516
showSoftKeyboard(): Promise&lt;void&gt;
Z
zhaolinglan 已提交
517

518
显示软键盘,使用Promise异步回调。参数个数为0,否则抛出异常。
Z
zhaolinglan 已提交
519

Z
zhaolinglan 已提交
520
**系统能力:**  SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
521 522 523

**返回值:**

Z
zhaolinglan 已提交
524 525 526
| 类型                | 说明                      |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
Z
zhaolinglan 已提交
527 528 529 530

**示例:**

```js
Z
zhaolinglan 已提交
531 532 533
InputMethodController.showSoftKeyboard().then(async (err) => {
    console.log('showSoftKeyboard success');
}).catch((err) => {
Z
zhaolinglan 已提交
534
    console.error('showSoftKeyboard promise err: ' + JSON.stringify(err));
Z
zhaolinglan 已提交
535 536 537
});
```

Z
zhaolinglan 已提交
538
### hideSoftKeyboard<sup>9+</sup> ###
Z
zhaolinglan 已提交
539

Z
zhaolinglan 已提交
540
hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
Z
zhaolinglan 已提交
541

542
隐藏软键盘,使用callback异步回调。参数个数为1,否则抛出异常。
Z
zhaolinglan 已提交
543

Z
zhaolinglan 已提交
544
**系统能力:**  SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
545 546 547

**参数:**

Z
zhaolinglan 已提交
548 549 550
| 参数名   | 参数类型                  | 必填 | 说明       |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。 |
Z
zhaolinglan 已提交
551 552 553 554

**示例:**

```js
Z
zhaolinglan 已提交
555
InputMethodController.hideSoftKeyboard((err) => {
Z
zhaolinglan 已提交
556
    if (err === undefined) {
Z
zhaolinglan 已提交
557
        console.info('hideSoftKeyboard success');
Z
zhaolinglan 已提交
558
    } else {
Z
zhaolinglan 已提交
559
        console.error('hideSoftKeyboard failed because : ' + JSON.stringify(err));
Z
zhaolinglan 已提交
560 561 562 563
    }
})
```

Z
zhaolinglan 已提交
564

Z
zhaolinglan 已提交
565
### hideSoftKeyboard<sup>9+</sup> ###
Z
zhaolinglan 已提交
566

Z
zhaolinglan 已提交
567
hideSoftKeyboard(): Promise&lt;void&gt;
Z
zhaolinglan 已提交
568

569
隐藏软键盘,使用Promise异步回调。参数个数为0,否则抛出异常。
Z
zhaolinglan 已提交
570

Z
zhaolinglan 已提交
571
**系统能力:**  SystemCapability.MiscServices.InputMethodFramework
Z
zhaolinglan 已提交
572 573 574

**返回值:**

Z
zhaolinglan 已提交
575 576 577
| 类型                | 说明                      |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
Z
zhaolinglan 已提交
578 579 580 581

**示例:**

```js
Z
zhaolinglan 已提交
582 583 584
InputMethodController.hideSoftKeyboard().then(async (err) => {
    console.log('hideSoftKeyboard success');
}).catch((err) => {
Z
zhaolinglan 已提交
585
    console.error('hideSoftKeyboard promise err: ' + JSON.stringify(err));
Z
zhaolinglan 已提交
586 587 588
});
```

589
## InputMethodSetting<sup>8+</sup>
Z
zhouyongfei 已提交
590

591
下列API示例中都需使用[getInputMethodSetting](#inputmethodgetinputmethodcontroller)回调获取到InputMethodSetting实例,再通过此实例调用对应方法。
Z
zhouyongfei 已提交
592

593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
### on('imeChange')<a name="imeChange"></a>

on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void

订阅输入法及子类型变化监听事件,使用callback回调返回变化了的输入法及子类型的相关实例。参数个数为3,参数1和参数2为napi_object,参数3为napi_function,否则抛出异常。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名   | 类型                            | 必填 | 说明                                                         |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                        | 是   | 设置监听类型。<br/>-type为‘imeChange’时表示订阅输入法及子类型变化监听事件。 |
| callback | [inputMethodProperty](#InputMethodProperty), [inputMethodSubtype](#InputMethodSubtype) | 是 | 回调返回输入法及子类型相关实例。 |

**示例:**

  ```js
  InputMethodEngine.on('imeChange', (inputMethodProperty, inputMethodSubtype) => {
      InputMethodProperty = inputMethodProperty;
      InputMethodSubtype = inputMethodSubtype;
  });
  ```

### off('imeChange')<a name="imeChange"></a>

on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void

取消订阅输入法及子类型变化监听事件,使用callback回调返回取消订阅的输入法及子类型的相关实例。必选参数个数为1,参数1为string,可选参数2为napi_function,否则抛出异常。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名   | 类型                            | 必填 | 说明                                                         |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                        | 是   | 设置监听类型。<br/>-type为‘imeChange’时表示取消订阅输入法及子类型变化监听事件。 |
| callback | [inputMethodProperty](#InputMethodProperty), [inputMethodSubtype](#InputMethodSubtype) | 否 | 回调返回输入法及子类型相关实例。 |

**示例:**

  ```js
  InputMethodAbility.off('imeChange');
  ```

### listInputMethodSubtype<sup>9+</sup>

listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): void

查询已安装的输入法子类型列表。使用callback形式返回结果。参数个数为2,否则抛出异常。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名   | 类型                                               | 必填 | 说明                   |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
| inputMethodProperty | InputMethodProperty| 是 | 要查询的输入法子类型的输入法属性
| callback | Array<[InputMethodSubtype](#InputMethodSubtype)> | 是   | 返回已安装输入法列表。 |

**示例:**

```js
InputMethodSetting.listInputMethodSubtype({"name":'', "id":''}, (err,data) => {
    if (err) {
        console.error('listInputMethod failed because: ' + JSON.stringify(err));
        return;
    }
    console.log('listInputMethod success');
 });
```

### listInputMethodSubtype<sup>9+</sup>

listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;

查询已安装的满足条件的输入法子类型列表。使用promise形式返回结果。参数个数为1,否则抛出异常。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型                                                        | 说明                   |
| ----------------------------------------------------------- | ---------------------- |
| Promise<Array<[InputMethodSubtype](#InputMethodSubtype)>> | 返回已安装输入法子类型列表。 |

**示例:**

```js
InputMethodSetting.listInputMethodSubtype().then((data) => {
    console.info('listInputMethodSubtype success');
}).catch((err) => {
    console.error('listInputMethodSubtype promise err: ' + err);
})
```

### listCurrentInputMethodSubtype<sup>9+</sup>

listCurrentInputMethodSubtype(callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): void
Z
zhaolinglan 已提交
692

693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
查询当前输入法的子类型列表。使用callback形式返回结果。参数个数为1,否则抛出异常。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名   | 类型                                               | 必填 | 说明                   |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
| callback | Array<[InputMethodSubtype](#InputMethodSubtype)> | 是   | 返回当前输入法的子类型列表。 |

**示例:**

```js
InputMethodSetting.listCurrentInputMethodSubtype((err,data) => {
    if (err) {
        console.error('listCurrentInputMethodSubtype failed because: ' + JSON.stringify(err));
        return;
    }
    console.log('listCurrentInputMethodSubtype success');
 });
```

### listCurrentInputMethodSubtype<sup>9+</sup>

listCurrentInputMethodSubtype(): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;

查询当前输入法的子类型列表。使用promise形式返回结果。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型                                                        | 说明                   |
| ----------------------------------------------------------- | ---------------------- |
| Promise<Array<[InputMethodSubtype](#InputMethodSubtype)>> | 返回当前输入法的子类型列表。 |

**示例:**

```js
InputMethodSetting.listCurrentInputMethodSubtype().then((data) => {
    console.info('listCurrentInputMethodSubtype success');
}).catch((err) => {
    console.error('listCurrentInputMethodSubtype promise err: ' + err);
})
```

### getInputMethods<sup>9+</sup>

getInputMethods(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
Z
zhaolinglan 已提交
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756

获取已激活/未激活输入法列表。参数enable取true,返回已激活输入法列表,取false返回未激活输入法列表。使用callback形式返回结果。参数个数为2,否则抛出异常。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名   | 类型                                                | 必填 | 说明                          |
| -------- | --------------------------------------------------- | ---- | ----------------------------- |
| enable   | boolean                                             | 是   | 指定返回已激活/未激活。       |
| callback | Array<[InputMethodProperty](#inputmethodproperty8)> | 是   | 返回已激活/未激活输入法列表。 |

**示例:**

```js
757
InputMethodSetting.getInputMethods(true, (err,data) => {
Z
zhaolinglan 已提交
758
    if (err) {
759
        console.error('getInputMethods failed because: ' + JSON.stringify(err));
Z
zhaolinglan 已提交
760 761
        return;
    }
762
    console.log('getInputMethods success');
Z
zhaolinglan 已提交
763 764 765
 });
```

766
### getInputMethods<sup>9+</sup>
Z
zhaolinglan 已提交
767

768
getInputMethods(enable: boolean): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
Z
zhaolinglan 已提交
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788

获取已激活/未激活输入法列表。参数enable取true返回已激活输入法列表,取false返回未激活输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型    | 必填 | 说明                    |
| ------ | ------- | ---- | ----------------------- |
| enable | boolean | 是   | 指定返回已激活/未激活。 |

**返回值:**

| 类型                                                         | 说明                          |
| ------------------------------------------------------------ | ----------------------------- |
| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | 返回已激活/未激活输入法列表。 |

**示例:**

```js
789 790
InputMethodSetting.getInputMethods(true).then((data) => {
    console.info('getInputMethods success');
Z
zhaolinglan 已提交
791
}).catch((err) => {
792
    console.error('getInputMethods promise err: ' + err);
Z
zhaolinglan 已提交
793 794 795
})
```

796
### listInputMethod<sup>deprecated</sup>
Z
zhouyongfei 已提交
797 798 799

listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void

800
查询已安装的输入法列表。使用callback形式返回结果。参数个数为1,否则抛出异常。
Z
zhouyongfei 已提交
801

802
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
803

804
**参数:**
B
bmeangel 已提交
805

T
explain  
tianyu 已提交
806 807
| 参数名   | 类型                                               | 必填 | 说明                   |
| -------- | -------------------------------------------------- | ---- | ---------------------- |
808
| callback | Array<[InputMethodProperty](#inputmethodproperty8)> | 是   | 返回已安装输入法列表。 |
Z
zhouyongfei 已提交
809

810
**示例:**
T
explain  
tianyu 已提交
811

812
```js
813
InputMethodSetting.listInputMethod((err,data) => {
Z
zhaolinglan 已提交
814
    if (err) {
Z
zhaolinglan 已提交
815
        console.error('listInputMethod failed because: ' + JSON.stringify(err));
816
        return;
817
    }
Z
zhaolinglan 已提交
818
    console.log('listInputMethod success');
819
 });
820
```
Z
zhouyongfei 已提交
821

822
### listInputMethod<sup>deprecated</sup>
Z
zhouyongfei 已提交
823

Z
zhaolinglan 已提交
824
listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
Z
zhouyongfei 已提交
825

826
查询已安装的输入法列表。使用promise形式返回结果。参数个数为0,否则抛出异常。
Z
zhouyongfei 已提交
827

828
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
829

830
**返回值:**
B
bmeangel 已提交
831

T
explain  
tianyu 已提交
832 833
| 类型                                                        | 说明                   |
| ----------------------------------------------------------- | ---------------------- |
834
| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | 返回已安装输入法列表。 |
Z
zhouyongfei 已提交
835

836
**示例:**
837 838

```js
Z
zhaolinglan 已提交
839
InputMethodSetting.listInputMethod().then((data) => {
Z
zhaolinglan 已提交
840
    console.info('listInputMethod success');
Z
zhaolinglan 已提交
841
}).catch((err) => {
Z
zhaolinglan 已提交
842
    console.error('listInputMethod promise err: ' + err);
Z
zhaolinglan 已提交
843
})
844
```
Z
zhouyongfei 已提交
845

846
### displayOptionalInputMethod<sup>deprecated</sup>
Z
zhouyongfei 已提交
847 848 849

displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void

850
显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。
Z
zhouyongfei 已提交
851

852
**系统能力**: SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
853

854
**参数:**
Z
zhouyongfei 已提交
855 856 857 858 859

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |

860
**示例:**
861 862

```js
863
InputMethodSetting.displayOptionalInputMethod((err) => {
Z
zhaolinglan 已提交
864
    if (err) {
Z
zhaolinglan 已提交
865
        console.error('displayOptionalInputMethod failed because: ' + JSON.stringify(err));
866 867
        return;
    }
Z
zhaolinglan 已提交
868
    console.info('displayOptionalInputMethod success');
869
});
870
```
Z
zhouyongfei 已提交
871

872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
### showOptionalInputMethods<sup>9+</sup>

showOptionalInputMethods(callback: AsyncCallback&lt;void&gt;): void

显示输入法选择对话框。使用callback形式返回结果。参数个数为1,否则抛出异常。

**需要权限**: ohos.permission.CONNECT_IME_ABILITY

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**参数:**

| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |

**示例:**

```js
InputMethodSetting.showOptionalInputMethods((err) => {
    if (err) {
        console.error('showOptionalInputMethods failed because: ' + JSON.stringify(err));
        return;
    }
    console.info('showOptionalInputMethods success');
});
```

Z
refresh  
zhouyongfei 已提交
900
### displayOptionalInputMethod
Z
zhouyongfei 已提交
901

902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926
displayOptionalInputMethod(): Promise&lt;void&gt;

显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。

**系统能力**: SystemCapability.MiscServices.InputMethodFramework

**返回值:**

| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**示例:**

```js
InputMethodSetting.displayOptionalInputMethod().then(() => {
    console.info('displayOptionalInputMethod success.(promise)');
}).catch((err) => {
    console.error('displayOptionalInputMethod promise err: ' + err);
})
```

### showOptionalInputMethods<sup>9+</sup>

  showOptionalInputMethods(): Promise&lt;void&gt;
Z
zhouyongfei 已提交
927

928
  显示输入法选择对话框。使用promise形式返回结果。参数个数为0,否则抛出异常。
Z
zhouyongfei 已提交
929

930
  **系统能力**: SystemCapability.MiscServices.InputMethodFramework
Z
zhouyongfei 已提交
931

932
**返回值:**
Z
zhouyongfei 已提交
933

Z
refresh  
zhouyongfei 已提交
934
| 类型 | 说明 |
Z
zhouyongfei 已提交
935
| -------- | -------- |
936
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
Z
zhouyongfei 已提交
937

938
**示例:**
939 940

```js
941
InputMethodSetting.showOptionalInputMethods().then(() => {
Z
zhaolinglan 已提交
942
    console.info('displayOptionalInputMethod success.(promise)');
Z
zhaolinglan 已提交
943
}).catch((err) => {
Z
zhaolinglan 已提交
944
    console.error('displayOptionalInputMethod promise err: ' + err);
Z
zhaolinglan 已提交
945
})
946
```