-3

I need to convert scalable pixels (sp) to pixels programmatically in Android. I already know how to convert dp to pixels, but how do I convert sp to pixels?

ILikePython
  • 150
  • 3
  • 15

1 Answers1

7

You can use the Apply Dimen using TypeValue, like below.

public int spToPx(float sp, Context context) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics());
}

It's an old question, you may found a lot of discussion about this

noman404
  • 928
  • 1
  • 8
  • 23