After a more-than-four-year hiatus, I have decided to start blogging again, this time hopefully, I will do more than one post per month, and hopefully this blog will be very helpful to both Android and iOS developers. That's right, in the time that I have been silent, I have moved from web development and JavaME/BB legacy development to full-time Android and iOS development. So here goes...

NB: This quick tip is written for Android Studio 2.0.

Using a custom font in Android is as simple as setting the TypeFace on a TextView. In order to do this you will need to copy your font file over to the assets directory in your project:

  1. If your project already has an assets directory, skip to step 2. If not, it will look something like the following:

    In the event that there is no assets directory, you will need to create one. This is done as follows:

    Once you have completed this step, you should see the assets directory in your project structure:

  2. Create a sub-directory for called fonts for your app's custom fonts in the assets folder

  3. Now copy and paste your font file(s) into the fonts folder:

  4. Now with your font in place, all you need to do in your Activity's onCreate() method is set your TextView to use it:

  5. TextView textViewTitleText = (TextView) findViewById(R.id.titleText);
    TypeFace customFont = TypeFace.createFromAsset(this, "fonts/Trattetello.ttf");
    textViewTitleText.setTypeFace(customFont);

And that's it! If you have not misspelt your font path, your font should now load once your text is set.

Other ways to achieve the same thing

There are two other ways of doing the same thing that I will hopefully share in a future post - one involves subclassing TextView and another requires custom styling (theming).

Happy coding :) !