当应用程序从后台打开时,Android 撰写文本字段会打开错误的键盘

问题描述 投票:0回答:1

嘿,我在 Jetpack Compose 方面遇到了一个非常奇怪的问题

TextField
。我这里有这个组件:

@Composable
fun AppTextField(
    modifier: Modifier = Modifier,
    value: String,
    label: String,
    singleLine: Boolean = true,
    readOnly: Boolean = false,
    enabled: Boolean = true,
    colors: TextFieldColors? = null,
    minLines: Int = 1,
    keyboardType: KeyboardType,
    visualTransformation: VisualTransformation = VisualTransformation.None,
    trailingIcon: @Composable (() -> Unit)? = null,
    leadingIcon: @Composable (() -> Unit)? = null,
    isError: Boolean = false,
    supportingText: @Composable (() -> Unit)? = null,
    onValueChanged: (String) -> Unit
){
    OutlinedTextField(value = value, onValueChange = {
        onValueChanged(it)
    },
        label = {
            Text(text = label)
        },
        singleLine = singleLine,
        shape = RoundedCornerShape(8.dp),
        modifier = modifier.fillMaxWidth(),
        colors = colors ?: OutlinedTextFieldDefaults.colors(
            focusedBorderColor = MaterialTheme.colorScheme.tertiary,
            unfocusedBorderColor = MaterialTheme.colorScheme.tertiary,
            disabledBorderColor = MaterialTheme.colorScheme.tertiary,
            disabledTextColor = MaterialTheme.colorScheme.onSurface,
            disabledLabelColor = MaterialTheme.colorScheme.onSurface,
        ),
        keyboardOptions = KeyboardOptions.Default.copy(keyboardType = keyboardType),
        visualTransformation = visualTransformation,
        trailingIcon = trailingIcon,
        isError = isError,
        supportingText = supportingText,
        readOnly = readOnly,
        enabled = enabled,
        leadingIcon = leadingIcon,
        minLines = minLines
        )
}

我在整个应用程序中都称这个组件为组件。它帮助我在各处保持相同的风格,甚至使应用程序组件更加模块化。现在的问题是我必须在我的一个屏幕中将

TextField KeyboardType
作为数字键盘。 因此,当我第一次打开屏幕并聚焦键盘时,一切看起来都很好,并且数字键盘会按预期打开。但每当我打开任何其他应用程序或只是将应用程序放在后台并再次打开它并专注于
TextField
键盘时,键盘会转到文本键盘而不是数字,甚至最糟糕的是,即使我单击文本键盘上的数字,也没有任何反应添加到我的文本字段的值中。 我到处搜索,尝试了每一种方法,但没有一个对我有用。 有人有这个问题吗? 我使用 Galaxy a24 和 Android 14 并使用 compose Material3 版本 1.2.1

android kotlin android-jetpack-compose material3
1个回答
0
投票

所以 bug 是在 jetpack compose Material 3 本身版本 1.2.1 内部,我将其升级到版本 1.3.0,一切运行顺利

© www.soinside.com 2019 - 2024. All rights reserved.