Java tutorial
//package com.java2s; import android.content.Context; import android.content.res.Resources; public class Main { public static int px2sp(Context context, float pxValue) { Resources resources = context.getResources(); final float fontScale = resources.getDisplayMetrics().scaledDensity; resources = null; return (int) (pxValue / fontScale + 0.5f); } }