Cleaner and more reusable approach is
define text size in dimens.xml
file inside res/values/
directory:
</resources>
<dimen name="text_medium">14sp</dimen>
</resources>
and then apply it to the TextView
:
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.text_medium));