Basically I have this inside XML, but I have to recreate it inside a code. How do I do it?
Just for completeness: Another solution (which I'd prefer) for the question is given here
setTextSize(float)expects a scaled pixel value. So,setTextSize(10)would give you the desired result. However,getDimension()andgetDimensionPixelSize()return the size in units of pixels.
So for your example it would be
setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.edTxt_text_size));
where is set in your dimens.xml file for example.