Change Keyboard Input Language Programmatically

后端 未结 2 2130

I am developing an application in which i need to allow the user to change the input keys shown in the default keyboard, upon request or by default, for example, i may promp

2条回答
  •  情书的邮戳
    2020-11-30 15:55

    After doing some research here and there found the answer, first of all you have to create a custom keyboard View which extends keyboardView and in it create static key value variable like

    static final int KEYCODE_LANGUAGE_SWITCH_ENG = -102;
    static final int KEYCODE_LANGUAGE_SWITCH_URDU = -103;
    

    after that in your IME class where you have implemented the inputMethodService, create the keyboards inside the onInitializeInterface override function. like

    mSymbolsKeyboard = new Keyboard(this, R.xml.qwerty2);
    mEngQwertyKeyboard = new Keyboard(this, R.xml.eng_qwerty);
    

    after this add these final static keys in the onKey override function as switch cases, and in the cases set the keyboards accordingly:

    setKeyboard(mEngQwertyKeyboard);
    

提交回复
热议问题