new*_*per 17 android kotlin android-jetpack-compose android-compose-textfield
使用 XML 创建 UI 时。有一个密码字段选项,其中密码对用户可见。开发人员所要做的就是设置inputType = TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
在 Jetpack Compose 中,可以选择创建 textField()。然后传入visualTransformation = PasswordVisualTransformation()
让打字变成点。然而,它不会像 XML 那样预览字母几秒钟,然后才变成点。
想知道是否有一个等效的 jetpack 撰写密码字段的功能,其中密码在变成点之前对用户可见几秒钟。
谢谢
Gab*_*tti 22
配置inputType
显示的键盘类型、可接受的字符和编辑文本的外观。
要1.0.0
拥有密码字段,您可以将 aTextField
与 一起使用KeyboardType.Password
:
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password)
另请检查此票证以进行进一步配置。
要将密码字段与视觉转换一起使用(使用掩码字符而不是原始文本):
var password by rememberSaveable { mutableStateOf("") }
TextField(
value = password,
onValueChange = { password = it },
label = { Text("Enter password") },
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password)
)
Run Code Online (Sandbox Code Playgroud)
要使用用户可见的密码字段,只需删除 VisualTransformation (并使用默认值VisualTransformation.None
):
var password by rememberSaveable { mutableStateOf("") }
TextField(
value = password,
onValueChange = { password = it },
label = { Text("Enter password") },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password)
)
Run Code Online (Sandbox Code Playgroud)
如果您想在两个选项之间切换:
var passwordVisibility by remember { mutableStateOf(false) }
TextField(
//...
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
visualTransformation = if (passwordVisibility) VisualTransformation.None else PasswordVisualTransformation(),
)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6398 次 |
最近记录: |