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

Add dimension in dimens.xml:

   <dimen name="text_medium">18sp</dimen>

Set the size in code:

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

Leave a Comment