tags:

views:

109

answers:

1

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 in sp?

thanks.

-mario_blizz

+1  A: 

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 * dm.scaledDensity; 
Dave Webb