如何在Android Compose中指定键盘语言



我正在编写Android Compose应用程序。我有一个TextField,其中包含已知语言的文本,例如德语。当用户点击TextField时,会弹出键盘。我希望键盘弹出预设与德语(鉴于它是目前的电话),以节省用户几次点击。我该怎么做呢?

我认为现在还没有这个功能的API。这是TextField的签名,

@Composable
fun TextField(
value: TextFieldValue,
onValueChange: (TextFieldValue) -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = LocalTextStyle.current,
label: @Composable (() -> Unit)? = null,
placeholder: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
isError: Boolean = false,
visualTransformation: VisualTransformation = VisualTransformation.None,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions(),
singleLine: Boolean = false,
maxLines: Int = Int.MAX_VALUE,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
shape: Shape =
MaterialTheme.shapes.small.copy(bottomEnd = ZeroCornerSize, bottomStart = ZeroCornerSize),
colors: TextFieldColors = TextFieldDefaults.textFieldColors()
)

与键盘相关的参数是keyboardOptions,如果您检查keyboardOptions的代码

class KeyboardOptions constructor(
val capitalization: KeyboardCapitalization = KeyboardCapitalization.None,
val autoCorrect: Boolean = true,
val keyboardType: KeyboardType = KeyboardType.Text,
val imeAction: ImeAction = ImeAction.Default
)
inline class KeyboardType internal constructor(@Suppress("unused") private val value: Int) {
override fun toString(): String {
return when (this) {
Text -> "Text"
Ascii -> "Ascii"
Number -> "Number"
Phone -> "Phone"
Uri -> "Uri"
Email -> "Email"
Password -> "Password"
NumberPassword -> "NumberPassword"
else -> "Invalid"
}
}
...
inline class ImeAction internal constructor(@Suppress("unused") private val value: Int) {
override fun toString(): String {
return when (this) {
None -> "None"
Default -> "Default"
Go -> "Go"
Search -> "Search"
Send -> "Send"
Previous -> "Previous"
Next -> "Next"
Done -> "Done"
else -> "Invalid"
}
}
...

您只能更改键盘类型和操作按钮,但此时没有更改语言的API。

最新更新