This question already has an answer here:
How can I use a custom font which was added in the asset folder in my xml? I know we can use setTypeface()
method in java, but we have to do this everywhere where we use that TextView
. So is there a better way?
The best way i found by googling is- Say if you want to use in TextView then we have to extend the Textview and have to set the font in that later we can use our customised Textview in our xml. I'll show the extended TextView below
We calling init() to set font in each of the costructors. Later we have to use this in our main.xml as shown below.
Update:
Be aware about the memory leak in pre-4.0 Android as mentioned by pandre.
Put your font file in
asset\fonts\fontname
Define three textview in your xml file then, put this code in your activity class: