In my application the user selects a language and I want to show the selected language when the keyboard opens (if it is present in the keyboard options). The keyboard provides that option, so it should be possible.
3 Answers
There is a big work around about how to do this - which is create your own keyboard, and to do this you'll have to know the keyboards you're aiming for. (which will be exact duplicate of the regular keyboard)
General guide on the subject here & code samples.
Create a custom keyboard View which extends keyboardView
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);
-
2I have seen this answer but still could not use it properly, could you please provide some details? – Belzebub Jul 25 '16 at 14:12
-
1
-
I know this answer is what I'm looking for but I still struggle to apply it. Is it possible to have a bit more details/explanations ? – Sebastien FERRAND Aug 23 '17 at 06:23
since api 24+ you can use Locale
mEditText.setImeHintLocales(new LocaleList(new Locale("en", "USA")));

- 794
- 7
- 15
this code is working fine
public class ParisaKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener {
public KeyboardView kv;
private Keyboard keyboard;
private Keyboard persianKeyboard;
@Override
public View onCreateInputView() {
kv = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard,null);
keyboard = new Keyboard(this, R.xml.qwerty);
persianKeyboard = new Keyboard(this, R.xml.persian);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
return kv;
}
@Override
public void swipeLeft() {
kv.setKeyboard(persianKeyboard);
}
@Override
public void swipeRight() {
kv.setKeyboard(keyboard);
}
so you can change language by swiping to left and right .

- 150
- 1
- 12