kumareloaded
kumareloaded

Reputation: 3952

Easiest way to use custom fonts? - android

the way i found for using custom fonts on my android app is using the below code

TextView txt = (TextView) findViewById(R.id.textView1);  
        Typeface font = Typeface.createFromAsset(getAssets(), "ABCD.TTF");  
        txt.setTypeface(font);

i've stored the ABCD.TTF in assets folder..

and ya it works, no probs in tat.. the thing is i have to add the above code for each and every texts,buttons,etc i have.. and its really a time consuming thing if theres lots of texts and buttons in various activity :(

what i need is an alternate method to do it, an easiest one to do it..

like using a single block of code not repeatative like the above to change the fonts for all the stuffs..

else doing it in the xml

or is there any way to add our custom font to the inbuilt typeface where normal,sans,serif,monospace are present.

Upvotes: 3

Views: 2437

Answers (2)

Vijay Vankhede
Vijay Vankhede

Reputation: 3058

You can use simple EasyFonts third party library to set variety of custom font to your TextView. By using this library you should not have to worry about downloading and adding fonts into the assets/fonts folder. Also about Typeface object creation.

Simply:

TextView myTextView = (TextView)findViewById(R.id.myTextView);
myTextView.setTypeface(EasyFonts.robotoThin(this));

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006604

like using a single block of code not repeatative like the above to change the fonts for all the stuffs..

There are a few ways of doing this already addressed in various StackOverflow answers. Here is that iterates over the children of a ViewGroup and apply a Typeface to all that implement TextView:
- https://stackoverflow.com/a/7580370/115145

else doing it in the xml

Sorry, this is not supported.

or is there any way to add our custom font to the inbuilt typeface where normal,sans,serif,monospace are present.

Sorry, this is not supported, except if you build your own firmware.

Upvotes: 1

Related Questions