How to assign text size in sp value using java code
If I assign an integer value to change a certain text size of a TextView using java code, the value is interpreted as pixel ( px ). Now does anyone know how to assign it in sp ? Santosh http://developer.android.com/reference/android/widget/TextView.html#setTextSize%28int,%20float%29 Example: textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 65); You can use a DisplayMetrics object to help convert between pixels and scaled pixels with the scaledDensity attribute . DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); pixelSize = (int)scaledPixelSize *