While developing an android app I found that everytime I was trying to use a custom font on a TextView I copied the same lines:
Obviously, that’s unnecessary and repetitive.
Why not just create a custom view? And more, why not adding the font through xml code?
We just have to extend from TextView and read from the attribute set the font string declared on its styleable resource. Just create an attrs.xml (or use an existing one) and add the following:
Now, you could declare on your xml layout like this:
And that’s all! pretty simple!