gpt4 book ai didi

android - 如何将android compose material icons传递给textField

转载 作者:行者123 更新时间:2023-12-05 00:19:08 24 4
gpt4 key购买 nike

我想使用 Material 图标作为参数传递给 textField。

@Composable
fun NormalTextField(
icon: () -> Unit, // how to pass material icon to textField
label: String
) {
val (text, setText) = mutableStateOf("")
TextField(
leadingIcon = icon,
value = text,
onValueChange = setText,
label = label
)
}

最佳答案

texfield 的 leadingIcon 参数是一个可组合函数(标签也是),所以一种方法是:

@Composable
fun Example() {
NormalTextField(label = "Email") {
Icon(
imageVector = Icons.Outlined.Email,
contentDescription = null
)
}
}

@Composable
fun NormalTextField(
label: String,
Icon: @Composable (() -> Unit)
) {
val (text, setText) = mutableStateOf("")
TextField(
leadingIcon = Icon,
value = text,
onValueChange = setText,
label = { Text(text = label) }
)
}

关于android - 如何将android compose material icons传递给textField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64135426/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com