在下面显示的代码中,我有一个接受用户输入的 TextField。如何将 drawable 添加到 TextField 的开头或结尾?我找不到任何用于设置 drawableStart 或 drawableEnd 的属性。
var text by rememberSaveable{ mutableStateOf("") }
TextField(
value = text,
modifier = Modifier
.fillMaxWidth(1f)
.padding(30.dp),
onValueChange = { text = it },
placeholder = { Text(text = "Email") },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email)
)
答案 0 :(得分:1)
TextField documentation 中有 leadingIcon
和 trailingIcon
属性。使用 leadingIcon 代替 drawableStart 和 trailingIcon 代替 drawableEnd。在下面找到示例实现:
var text by rememberSaveable{ mutableStateOf("") }
TextField(
value = text,
modifier = Modifier
.fillMaxWidth(1f)
.padding(30.dp),
onValueChange = { text = it },
placeholder = { Text(text = "Email") },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email),
leadingIcon = { Icon(Icons.Filled.Favorite, contentDescription = "Localized description") },
trailingIcon = { Icon(Icons.Filled.Info, contentDescription = "Localized description") }
)