Tutorial by Examples

Go to the (project folder) Then app -> src -> main. Create folder 'assets -> fonts' into the main folder. Put your 'fontfile.ttf' into the fonts folder.
private Typeface myFont; // A good practice might be to call this in onCreate() of a custom // Application class and pass 'this' as Context. Your font will be ready to use // as long as your app lives public void initFont(Context context) { myFont = Typeface.createFromAsset(context.getAss...
public void setFont(TextView textView) { textView.setTypeface(myFont); }
TextViewPlus.java: public class TextViewPlus extends TextView { private static final String TAG = "TextView"; public TextViewPlus(Context context) { super(context); } public TextViewPlus(Context context, AttributeSet attrs) { super(context, attrs)...
Drawing text in canvas with your font from assets. Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/SomeFont.ttf"); Paint textPaint = new Paint(); textPaint.setTypeface(typeface); canvas.drawText("Your text here", x, y, textPaint);
Loading custom fonts can be lead to a bad performance. I highly recommend to use this little helper which saves/loads your already used fonts into a Hashtable. public class TypefaceUtils { private static final Hashtable<String, Typeface> sTypeFaces = new Hashtable<>(); /** * Get...
public class ReplaceFont { public static void changeDefaultFont(Context context, String oldFont, String assetsFont) { Typeface typeface = Typeface.createFromAsset(context.getAssets(), assetsFont); replaceFont(oldFont, typeface); } private static void replaceFont(String oldFont, Type...
Android O changes the way to work with fonts. Android O introduces a new feature, called Fonts in XML, which allows you to use fonts as resources. This means, that there is no need to bundle fonts as assets. Fonts are now compiled in an R file and are automatically available in the system as a reso...

Page 1 of 1