Jetpack Compose 前导图标不可见

Bri*_*n O 2 android android-jetpack-compose

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

leadingIcon = { Icon(Icons.Filled.Search) },
Run Code Online (Sandbox Code Playgroud)

但 IDE 突出显示,None of the following functions can be called with the arguments supplied.自类Icon(). 所以我尝试了另一种选择,如下所示

 leadingIcon = { (Icons.Filled.Search) },
Run Code Online (Sandbox Code Playgroud)

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

Nag*_*obi 5

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

你应该尝试:

leadingIcon = { Icon(imageVector = Icons.Filled.Search, contentDescription = null) }
Run Code Online (Sandbox Code Playgroud)

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