How to create custom fonts in android studio

Eric Ong picture Eric Ong · Nov 15, 2013 · Viewed 27.1k times · Source

I need to add new fonts to my project where do i create it in android studio

Can someone advise if i create it in the correct directory in android studio?

I tried putting the fonts folder same location as SRC folder but didn't work out

my code is

Typeface fontRobo = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Black.ttf");
viewTotalValue.setText(total.toString());

Is this correct? please advise

Answer

Mina Fawzy picture Mina Fawzy · Jun 13, 2015

if you use android studio , you should create assets folder from right click at

app ---> New --->Folder --->Assets Folder

enter image description here

choose destination to your assets folder default main

enter image description here

create directory called fonts in assets then place your font

enter image description here

|assets

    |-----------------fonts

        |-------------------Roboto-Black.ttf

|java

|res

AndroidManifest.xml

finally use this code

Typeface fontRobo = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Black.ttf");
viewTotalValue.setText(total.toString()); 
viewTotalValue.setTypeface(fontRobo );