Hi, I'm trying to add password visibility toggle t...
# compose
e
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
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
it’s fron the material library.
androidx.compose.material.icons.Icons
Copy code
implementation("androidx.compose.material:material:1.1.0")
s
You also need material-icons
Unless I'm remembering incorrectly.
e
material icons extended worked fine, thanks
s
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
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
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
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
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