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).
TextView
px
Now does
When the accepted answer doesn't work (for example when dealing with Paint) you can use:
float spTextSize = 12; float textSize = spTextSize * getResources().getDisplayMetrics().scaledDensity; textPaint.setTextSize(textSize);