据我所知,下面的最小示例应该创建一个自动将键盘设置为全部大写的 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)
)
}
}
}
}
您可以尝试将 TextFieldValue 更改为 String