Nital Nital - 22 days ago 11
Android Question

Convert pixels to sp

I need the current

TextSize
of the
TextView
in
sp
units.

But
getTextSize()
returns the size in
pixels
. So is there a way to
convert pixels to sp
?

Answer

See the DisplayMetrics class, it has fields for densityDpi and scaledDensity.

Comments