1# Setting Input Method Subtypes 2 3The input method subtypes allow the input method to switch to a specific mode or language, for example, the Chinese or English keyboard. 4 5## Configuring and Implementing an Input Method Subtype 6 71. 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. 8 ```ts 9 { 10 "module": { 11 // ... 12 "extensionAbilities": [ 13 { 14 "description": "InputMethodExtDemo", 15 "icon": "$media:icon", 16 "name": "InputMethodExtAbility", 17 "srcEntry": "./ets/InputMethodExtensionAbility/InputMethodService.ts", 18 "type": "inputMethod", 19 "exported": true, 20 "metadata": [ 21 { 22 "name": "ohos.extension.input_method", 23 "resource": "$profile:input_method_config" 24 } 25 ] 26 } 27 ] 28 } 29 } 30 ``` 31 322. 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 [BCP 47](https://tools.ietf.org/html/bcp47). 33 ``` 34 { 35 "subtypes": [ 36 { 37 "icon": "$media:icon", 38 "id": "InputMethodExtAbility", 39 "label": "$string:english", 40 "locale": "en-US", 41 "mode": "lower" 42 }, 43 { 44 "icon": "$media:icon", 45 "id": "InputMethodExtAbility1", 46 "label": "$string:chinese", 47 "locale": "zh-CN", 48 "mode": "lower" 49 } 50 ] 51 } 52 ``` 53 543. 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. 55 56 ```ts 57 import { InputMethodSubtype, inputMethodEngine } from '@kit.IMEKit'; 58 59 let panel: inputMethodEngine.Panel; 60 let inputMethodAbility: inputMethodEngine.InputMethodAbility = inputMethodEngine.getInputMethodAbility(); 61 inputMethodAbility.on('setSubtype', (inputMethodSubtype: InputMethodSubtype) => { 62 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. 63 if (inputMethodSubtype.id == 'InputMethodExtAbility') {// Different soft keyboard UIs are loaded according to the subtype. 64 panel.setUiContent('pages/Index'); 65 } 66 if (inputMethodSubtype.id == 'InputMethodExtAbility1') { // Different soft keyboard UIs are loaded according to the subtype. 67 panel.setUiContent('pages/Index1'); 68 } 69 }); 70 ``` 71 72## Obtaining Information About Input Method Subtypes 73 741. To obtain the current subtype of the current input method, call [getCurrentInputMethodSubtype](../reference/apis-ime-kit/js-apis-inputmethod.md#inputmethodgetcurrentinputmethodsubtype9). 75 762. To obtain all subtypes of the current input method, call [listCurrentInputMethodSubtype](../reference/apis-ime-kit/js-apis-inputmethod.md#listcurrentinputmethodsubtype9). 77 783. To obtain all subtypes of a specified input method, call [listInputMethodSubtype](../reference/apis-ime-kit/js-apis-inputmethod.md#listinputmethodsubtype9). 79 80 81## Switching Between Input Method Subtypes 82 831. To switch to another subtype of the current input method, call [switchCurrentInputMethodSubtype](../reference/apis-ime-kit/js-apis-inputmethod.md#inputmethodswitchcurrentinputmethodsubtype9). 84 852. To switch to a specified subtype of a specified input method, call [switchCurrentInputMethodAndSubtype](../reference/apis-ime-kit/js-apis-inputmethod.md#inputmethodswitchcurrentinputmethodandsubtype9). 86 87 <!--no_check-->