Send info from EditText to IME
-
23-10-2019 - |
Question
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?
Solution
Your idea doesn't sound bad. IME's code check for the InputType
in a switch block and the default keyboard layout is shown if the InputType
didn't match.
You can also provide a logic in onCreate()
method of your Activity
to check which input method is active and with that info choose which inputType
your EditText
should have.