https://kotlinlang.org logo
m

Marcin Wisniowski

01/22/2022, 7:08 PM
How do I draw
Text
with a specific size in pixels? It seems you can only specify the size in
sp
and
em
.
f

Filip Wiesner

01/22/2022, 7:37 PM
You can convert pixels to
Sp
with `Density`:
Copy code
val density = LocalDensity.current
val spFromPx = with(density) { 12.toSp() }
But be aware that the
SP
unit exists for a reason and the
Text
composable does not take pixels intentionally.
m

Marcin Wisniowski

01/22/2022, 7:41 PM
I know it's usually a bad idea, but I have a specific use-case here which requires it. Thanks for the conversion idea, that works!
👌 1
3 Views