Jetpack Compose KeyboardCapitalization 选项被忽略?

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

据我所知,下面的最小示例应该创建一个自动将键盘设置为全部大写的 TextField。

不确定我是否做错了什么,但至少在我的手机上,大写选项会被忽略,键盘会保持小写,除非我按 Shift 键。

有什么想法可能是什么原因吗?

class MainActivity : ComponentActivity() {
    @OptIn(ExperimentalMaterial3Api::class)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            // A surface container using the 'background' color from the theme
            Surface(
                modifier = Modifier.fillMaxSize(),
                color = MaterialTheme.colorScheme.background
            ) {
                //IngredientOverview(listOfFoods)
                var text by remember { mutableStateOf(TextFieldValue("")) }
                TextField(
                    value = text,
                    onValueChange = {
                        text = it
                    },
                    keyboardOptions = KeyboardOptions(
                        capitalization = KeyboardCapitalization.Characters)
                )
            }
        }
    }
}
kotlin keyboard android-jetpack-compose
1个回答
0
投票

您可以尝试将 TextFieldValue 更改为 String

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