https://kotlinlang.org logo
#compose
Title
# compose
e

Enrico Saggiorato

02/28/2022, 6:23 PM
Hi, I'm trying to add password visibility toggle to a TextField but I cannot find Visibility icon. Do I have to install some extra libraries? I'm trying to use Icons.Filled.Visibility but Android Studio shows an error and is not able to import anything
s

Sean Proctor

02/28/2022, 6:29 PM
I'm not sure which package it's in. You might need to add a dependency on androidx.compose.material:material-icons-extended
2
m

mattinger

02/28/2022, 6:31 PM
it’s fron the material library.
androidx.compose.material.icons.Icons
Copy code
implementation("androidx.compose.material:material:1.1.0")
s

Sean Proctor

02/28/2022, 6:33 PM
You also need material-icons
Unless I'm remembering incorrectly.
e

Enrico Saggiorato

02/28/2022, 6:38 PM
material icons extended worked fine, thanks
s

Sean Proctor

02/28/2022, 6:39 PM
Yeah, I think you're right. That package should include the basic icons. I guess visibility is not one of them. It's really hard to find the answer to that though
a

Alex Vanyo

02/28/2022, 6:42 PM
Yeah, it’s documented here: https://developer.android.com/reference/kotlin/androidx/compose/material/icons/package-summary There’s a core set of icons available in the artifact
androidx.compose.material:material-icons-core
, which is automatically included if you include
androidx.compose.material:material
or
androidx.compose.material3:material3
That list of core icons is here: https://developer.android.com/reference/kotlin/androidx/compose/material/icons/filled/package-summary To use anything outside of that core list requires directly specifying
androidx.compose.material:material-icons-extended
, which then brings them all in. I think the best reference to that full list is https://fonts.google.com/icons
m

Mike Wolfson

02/28/2022, 8:32 PM
These are just Vectors, so I feel like it is not a lot of size to bring the full icon package in. It isn't like bringing multiple differently sized PNGs into the package.
l

Louis Pullen-Freilich [G]

02/28/2022, 10:56 PM
These are just Vectors, so I feel like it is not a lot of size to bring the full icon package in.
If you don’t use r8 / similar, it’s a huge amount of size because of the sheer number of icons 🙂 It’s less than PNGs, sure, but it’s still ~9000 generated classes with vector code
There’s some more information in the resources guide here
c

Colton Idle

03/01/2022, 5:50 AM
Also, if anyone is wondering how to just add the password visibility toggle in the first place... its available here in the compose samples https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]s/TextFieldSamples.kt;l=166?q=compose%20sample%20text%20input
4 Views