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?
Asked
Active
Viewed 5,497 times
1 Answers
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