How to assign text size in sp value using java code

后端 未结 11 2055
無奈伤痛
無奈伤痛 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:58

    From Api level 1, you can use the public void setTextSize (float size) method.

    From the documentation:

    Set the default text size to the given value, interpreted as "scaled pixel" units. This size is adjusted based on the current density and user font size preference.

    Parameters: size -> float: The scaled pixel size.

    So you can simple do:

    textView.setTextSize(12); // your size in sp
    

提交回复
热议问题