+ 3

Custom fonts in Android app

Do anyone know how to add custom fonts in your Android project?

30th May 2017, 4:04 AM
Taabeer Murtaza
Taabeer Murtaza - avatar
6 odpowiedzi
+ 4
import android.graphics.Typeface or learn more about typeface https://developer.android.com/reference/android/graphics/Typeface.html
30th May 2017, 6:21 AM
MR Programmer
MR Programmer - avatar
+ 6
abc.ttf is the font file Go to the (project folder) Then app>src>main Create folder 'assets>fonts' into the main folder. Put your 'abc.ttf' into the fonts folder. AssetManager am = context.getApplicationContext().getAssets(); typeface = Typeface.createFromAsset(am, String.format(Locale.US, "fonts/%s", "abc.ttf")); setTypeface(typeface); or try this way: TextView tx = (TextView)findViewById(R.id.textview1); Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/abc.ttf"); tx.setTypeface(custom_font);
30th May 2017, 6:03 AM
MR Programmer
MR Programmer - avatar
+ 4
thanks @Mr Programmer , can you please give me a demo source code, I wanted to make an app with Copperplate script fonts. A demo might be self explanatory.
30th May 2017, 6:30 AM
Taabeer Murtaza
Taabeer Murtaza - avatar
+ 2
I used that if you say I can post the code but my app crashes Everytime...... don't know what's wrong.... tried alternative methods but all in vain......
30th May 2017, 4:24 AM
Taabeer Murtaza
Taabeer Murtaza - avatar
+ 2
I tried this, gives an error on line: "typeface = Typeface.createFrom......" what are the requirements of this code? I mean like android.support.blablabla...
30th May 2017, 6:18 AM
Taabeer Murtaza
Taabeer Murtaza - avatar
+ 1
there is a class *TypeFace* . u should store ur font type face file (.ttf file) in *raw/assets* folder. then u can access it and apply to textviews. google on "typeface android", ull come to know
30th May 2017, 4:10 AM
P Sandesh Baliga
P Sandesh Baliga - avatar