Set Custom Fonts in android

 You can define your own custom fonts for the strings in your application. You just need to download the required font from the internet, and then place it in assets/fonts folder.

After putting fonts in the assets folder under fonts folder, you can access it in your java code through Typeface class. First , get the reference of the text view in the code. Its syntax is given below 

TextView tx = (TextView)findViewById(R.id.textview1);

The next thing you need to do is to call static method of Typeface class createFromAsset() to get your custom font from assets. Its syntax is given below −

Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/font name.ttf");

The last thing you need to do is to set this custom font object to your TextView Typeface property. You need to call setTypeface() method to do that. Its syntax is given below −

tx.setTypeface(custom_font);

Apart from these Methods, there are other methods defined in the Typeface class , that you can use to handle Fonts more effectively.

Sr.No Method & description
1

create(String familyName, int style)

Create a Typeface object given a family name, and option style information

2

create(Typeface family, int style)

Create a Typeface object that best matches the specified existing Typeface and the specified Style

3

createFromFile(String path)

Create a new Typeface from the specified font file

4

defaultFromStyle(int style)

Returns one of the default Typeface objects, based on the specified style

5

getStyle()

Returns the Typeface's intrinsic style attributes