I’m writing a language learning app, currently only German<->Russian.
There are several EditTexts where the user is supposed to enter text in one or the other language. As these languages use different alphabets, the app uses its own soft keyboard by implementing InputMethodService and providing both Latin and Cyrillic keyboard layout. It is known for each EditText field which language is expected.
What I would like is that, e.g., whenever an EditText field expecting Russian is in focus, the Cyrillic keyboard layout should be displayed. When selected, the EditText should pass some constant on to the IME, which the latter can use to decide whether to display in Latin or Cyrillic mode.
Ideally, one would simply specify some custom InputType for the EditText but that doesn’t seem to be possible, does it? What is the correct approach here?
Your idea doesn’t sound bad. IME’s code check for the
InputTypein a switch block and the default keyboard layout is shown if theInputTypedidn’t match.You can also provide a logic in
onCreate()method of yourActivityto check which input method is active and with that info choose whichinputTypeyourEditTextshould have.