1# Setting Input Method Subtypes 2<!--Kit: IME Kit--> 3<!--Subsystem: MiscServices--> 4<!--Owner: @illybyy--> 5<!--Designer: @andeszhang--> 6<!--Tester: @murphy1984--> 7<!--Adviser: @zhang_yixin13--> 8 9The input method subtypes allow the input method to switch to a specific mode or language, for example, the Chinese or English keyboard. 10 11## Configuring and Implementing an Input Method Subtype 12 131. Implement an **InputMethodExtensionAbility** instance for an input method, which will be shared by all subtypes of the input method. Add **metadata** with the name **ohos_extension.input_method** to the [module.json5](../quick-start/module-configuration-file.md) file to configure resource information for all subtypes. 14 ```ts 15 { 16 "module": { 17 // ... 18 "extensionAbilities": [ 19 { 20 "description": "InputMethodExtDemo", 21 "icon": "$media:icon", 22 "name": "InputMethodExtAbility", 23 "srcEntry": "./ets/InputMethodExtensionAbility/InputMethodService.ts", 24 "type": "inputMethod", 25 "exported": true, 26 "metadata": [ 27 { 28 "name": "ohos.extension.input_method", 29 "resource": "$profile:input_method_config" 30 } 31 ] 32 } 33 ] 34 } 35 } 36 ``` 37 382. Configure the subtype fields. For details about the fields, see [InputMethodSubtype](../reference/apis-ime-kit/js-apis-inputmethod-subtype.md#inputmethodsubtype). Make sure your configuration is in strict compliance with the configuration file and field specifications. For details about how to configure the **locale** field, see [i18n-locale-culture](.././internationalization/i18n-locale-culture.md#how-it-works). 39 ``` 40 { 41 "subtypes": [ 42 { 43 "icon": "$media:icon", 44 "id": "InputMethodExtAbility", 45 "label": "$string:english", 46 "locale": "en-US", 47 "mode": "lower" 48 }, 49 { 50 "icon": "$media:icon", 51 "id": "InputMethodExtAbility1", 52 "label": "$string:chinese", 53 "locale": "zh-CN", 54 "mode": "lower" 55 } 56 ] 57 } 58 ``` 59 603. Register a listener in the input method application for subtype changes, so as to load a subtype-specific soft keyboard UI. You can also use a state variable to change the soft keyboard layout. 61 62 ```ts 63 import { InputMethodSubtype, inputMethodEngine } from '@kit.IMEKit'; 64 65 let panel: inputMethodEngine.Panel; 66 let inputMethodAbility: inputMethodEngine.InputMethodAbility = inputMethodEngine.getInputMethodAbility(); 67 inputMethodAbility.on('setSubtype', (inputMethodSubtype: InputMethodSubtype) => { 68 let subType = inputMethodSubtype; // Save the current input method subtype. You can also change the state variable value here, based on which different layouts are displayed. 69 if (inputMethodSubtype.id == 'InputMethodExtAbility') {// Different soft keyboard UIs are loaded according to the subtype. 70 panel.setUiContent('pages/Index'); 71 } 72 if (inputMethodSubtype.id == 'InputMethodExtAbility1') { // Different soft keyboard UIs are loaded according to the subtype. 73 panel.setUiContent('pages/Index1'); 74 } 75 }); 76 ``` 77 78## Obtaining Information About Input Method Subtypes 79 801. To obtain the current subtype of the current input method, call [getCurrentInputMethodSubtype](../reference/apis-ime-kit/js-apis-inputmethod.md#inputmethodgetcurrentinputmethodsubtype9). 81 822. To obtain all subtypes of the current input method, call [listCurrentInputMethodSubtype](../reference/apis-ime-kit/js-apis-inputmethod.md#listcurrentinputmethodsubtype9). 83 843. To obtain all subtypes of a specified input method, call [listInputMethodSubtype](../reference/apis-ime-kit/js-apis-inputmethod.md#listinputmethodsubtype9). 85 86 87## Switching Between Input Method Subtypes 88 891. To switch to another subtype of the current input method, call [switchCurrentInputMethodSubtype](../reference/apis-ime-kit/js-apis-inputmethod.md#inputmethodswitchcurrentinputmethodsubtype9). 90 912. To switch to a specified subtype of a specified input method, call [switchCurrentInputMethodAndSubtype](../reference/apis-ime-kit/js-apis-inputmethod.md#inputmethodswitchcurrentinputmethodandsubtype9). 92