Monday, February 21, 2011

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

thanks.

-mario_blizz

From stackoverflow
  • 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; 
    

0 comments:

Post a Comment