How to set unit for Paint.setTextSize()

Yverman picture Yverman · Jun 17, 2010 · Viewed 46.9k times · Source

Is it possible to change the unit for Paint.setTextSize()? As far as I know, it's pixel but I like to set the text size in DIP for multiple screen support.

Answer

Felipe Caldas picture Felipe Caldas · Jun 14, 2012

I know this topic is old and already answered but I would like to also suggest this piece of code:

int MY_DIP_VALUE = 5; //5dp

int pixel= (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                              MY_DIP_VALUE, getResources().getDisplayMetrics());