Android - setTextSize()

By xngo on June 23, 2019

You can programmatically set the text size with the following code.

textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);

Or, set the text size in res/values/dimensions.xml as follows.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="textsize">15sp</dimen>
</resources>

Then, call the resource file like the following.

textView.setTextSize(getResources().getDimension(R.dimen.textsize));

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.