我正在使用 Android 开发者网站提供的 literally one of the examples Jetpack compose 实现 PasswordInput
可组合:
@Composable
fun PasswordInput() {
var password by remember { mutableStateOf("admin") }
TextField(
value = password,
onValueChange = { password = it },
label = { Text(text = stringResource(id = R.string.prompt_password)) },
modifier = Modifier
.fillMaxWidth(),
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password)
)
}
这里我的密码默认为“admin”,长度为五个字符。它显示五个星号。
但是如果用户在那里按下回车键,密码字段就会变成六个字符。
问题:
答案 0 :(得分:0)
我来回答我的问题。它需要 singleLine = true
,文档中没有提到。
固定代码:
@Composable
fun PasswordInput() {
var password by rememberSaveable { mutableStateOf("") }
TextField(
value = password,
onValueChange = { password = it },
maxLines = 1,
singleLine = true,
label = { Text(text = stringResource(id = R.string.prompt_password)) },
modifier = Modifier
.fillMaxWidth(),
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password)
)
}