Jetpack Compose leadingIcon 不可见

Jetpack Compose leadingIcon not visible

我目前正在使用 Jetpack 撰写文本字段。我尝试在文本字段上添加前导图标,如下所示

leadingIcon = { Icon(Icons.Filled.Search) },

但是 IDE 自 classIcon() 强调 None of the following functions can be called with the arguments supplied.。所以我尝试了另一种选择,如下所示

 leadingIcon = { (Icons.Filled.Search) },

没有抛出异常,所以我认为它会起作用,但现在前导图标不可见。 我可能做错了什么? 提前致谢

Icon 可组合项还需要 contentDescription 属性。
你必须使用

leadingIcon = { Icon(Icons.Filled.Search, "contentDescription") },

您的第一种方法是正确的,但由于 1.0.0-alpha11 contentDescription 是必需参数。基本上,该框架迫使您考虑 可访问性

你应该试试:

leadingIcon = { Icon(imageVector = Icons.Filled.Search, contentDescription = null) }

有关该决定的更多信息,请参阅 Leland 的这条推文: https://twitter.com/intelligibabble/status/1355209643614584833?s=20