I'm coding an app in Android Compose. I have a TextField with text in known language, say German. When a user taps the TextField, the keyboard pops up. I want the keyboard to pop up preset with German language (given it is present on the phone) to save the user few taps. How can I do it?
As of Compose 1.7.0-beta06
, a new parameter has been added to the Keyboard's ImeOptions called hintLocales
With this, you can specify the languages you want your ime to switch to based on the context in your app, directly addressing the OP's question.
From the docs:
List of the languages that the user is supposed to switch to no matter what input method subtype is currently used. This special "hint" can be used mainly for, but not limited to, multilingual users who want IMEs to switch language based on editor's context. Pass LocaleList.Empty to express the intention that a specific hint should not be set.
Sample usage:
OutlinedTextField(
...
keyboardOptions = KeyboardOptions.Default.copy(
hintLocales = LocaleList(Locale("ar"))
)
)