How to set text size using dimension from xml at runtime programmatically?

后端 未结 3 935
醉梦人生
醉梦人生 2020-12-12 18:05

In dimens.xml, I have:

18sp

In runtime, I get this value and set the text size of a text vi

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 18:27

    Add dimension in dimens.xml:

       18sp
    

    Set the size in code:

    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.text_medium));
    

提交回复
热议问题