I recently finished developing my android application. I used sp (Scaled pixels) for all textSize. The problem is when i adjusted the system font-size, my application\'s fon
I think use dp
is the best way, but in some case you may want to use a font style, but the style is using sp
, you can convert sp
to dp
by:
fun TextView.getSizeInSp() = textSize / context.resources.displayMetrics.scaleDensity
fun TextView.convertToDpSize() = setTextSize(TypedValue.COMPLEX_UNIT_DIP, getSizeInSp())
so you can use the sp
value from style without dynamic font size, and no need to hardcode the font size