Setting textSize programmatically

后端 未结 2 385
星月不相逢
星月不相逢 2020-12-24 00:32
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.result_font));

The following code works, but the R.dimen

2条回答
  •  佛祖请我去吃肉
    2020-12-24 01:05

    You have to change it to TypedValue.COMPLEX_UNIT_PX because getDimension(id) returns a dimen value from resources and implicitly converted to px.

    Java:

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

    Kotlin:

    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 
                         resources.getDimension(R.dimen.result_font))
    

提交回复
热议问题