Brian O
Brian O

Reputation: 192

Jetpack Compose leadingIcon not visible

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

Upvotes: 6

Views: 7617

Answers (2)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364401

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

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

Upvotes: 4

Róbert Nagy
Róbert Nagy

Reputation: 7670

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

Upvotes: 11

Related Questions