android - Jetpack compose:将可绘制对象添加到 TextField 的开头
问题描述
在下面显示的代码中,我有一个接受用户输入的 TextField。如何在 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)
)
解决方案
TextField 文档中有一个leadingIcon
andtrailingIcon
属性。使用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") }
)
推荐阅读
- pandas - MultiIndex 上的 DataFrame groupby() 然后应用于多个列会导致广播问题
- android - Tensorflow Lite GPUdelegate 在最后一层给出“Dimensions are not BHWC”错误。但对我来说,这一层似乎是 BHWC,就像其他所有层一样
- ruby-on-rails - 查询关联数据时急切加载关联
- java - 使用 XSLT 解析 XML 时如何处理多个小数?
- python - 使用 django 电子邮件创建 txt 文件模板
- node.js - 公牛队列包配置混乱
- python - list[:] 的浅拷贝
- java - 在 EJB 中安排类似 Cron 的作业
- python - 无法导入 normalize_corpus python 3
- reactjs - 测试用 recompose 组成的多个 HOC