Java tutorial
//package com.java2s; import android.content.Context; import android.content.res.Resources; public class Main { public static float pixelsToSp(float px, Context context) { Resources resources = context.getResources(); float scaledDensity = resources.getDisplayMetrics().scaledDensity; return px / scaledDensity; } }