Jetpack Compose leadingIcon not visible

Viewed 2570

I am currently working with the jetpack compose text field. I tried adding a leading icon on the text field like below

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

but the IDE highlighted that None of the following functions can be called with the arguments supplied. since the classIcon(). So I tried another option, shown below

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

There was no exception thrown so I assumed that it would work, but now the leading Icon is not visible. What could I be doing wrong?. Thanks in advance

2 Answers

Your first approach is correct, but since 1.0.0-alpha11 contentDescription is a required parameter. Basically the framework is forcing you to think about accessibility.

You should try with:

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

See this tweet from Leland for more information about the decision: https://twitter.com/intelligibabble/status/1355209643614584833?s=20

The Icon composable requires also the contentDescription property.
You have to use

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