How to assign text size in sp value using java code

后端 未结 11 2041
無奈伤痛
無奈伤痛 2020-12-04 05:14

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

11条回答
  •  鱼传尺愫
    2020-12-04 05:59

    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);
    

提交回复
热议问题