Quick Tip: Using a Custom Font in Android

January 20, 2016
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");

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 :) !


BlackBerry: Cannot run program "jar" error

July 25, 2011
Been a while since I posted (that's an understatement), and I figured I should start again. I will try to be more consistent this time. I am currently working on BlackBerry projects and would like to share any interesting stuff that I discover through this blog. Hopefully someone will bump into it in a time of need.

While developing BlackBerry applications you may come across this error message:

I/O Error: Cannot run program "jar": CreateProcess error=2, The system cannot find the file specifie...
Continue reading...

Google Chrome for Linux

December 21, 2009
Good news!

Google Chrome Beta is now available on Linux! Coming in at a neat 12MB download, the .deb package that I downloaded was a snap to install from my Kubuntu Hardy 8.04.3 after clicking. There are also rpm and .sh for Red Hat-based and other Linux distros out there. So far I'm happy with Chrome's performance on Linux, but my favourite browser is still Mozilla Firefox, but I must say that Chrome's developer tools are worth having a look at. 

You can get yourself a copy at http://www.googl...
Continue reading...

Configuring a Kohana website/application - Kohana Series

October 7, 2009
Tip #3 - Configuring a Kohana website/application

0. Download Kohana from the Kohana website: http://www.kohanaphp.com/download.
1. Extract the downloaded into a directory accessible to your web server (let's say Your_DocumentRoot_Directory/k for the purposes of this tutorial)
2. Ensure that your web server has read/write/execute access to all files within your Kohana directory (k). If you are on Linux, you may need to do something to this effect: chmod -R 777 Your_DocumentRoot_Directory/k, e.g ...
Continue reading...

Tip #1 - JavaME emulator wont run on Kubuntu

September 29, 2009

So I decided to learn Java ME development. And I came across a blog called - well what do you know - the Java ME Blog, over at http://www.javameblog.com/.  Using the info on this blog along with what I found on the awesome java.net (http://today.java.net/pub/a/today/2005/02/09/j2me1.html), I was able to write a small MIDlet, and build it. Ah, now to run it... Not so fast; I kept getting an error message along these lines:

Starting emulator in execution mode
java.io.IOException: java.i...
Continue reading...

Who am I?

Tash Pemhiwa The simple answer is Tashinga N. Pemhiwa. Hailing from Zimbabwe, Africa, I grew up in Bulawayo in the Matebeleland region of Zim. I am first born in a family of six children, with two brothers and three sisters. My favourite activity is singing and professionally I enjoy web & software development. I am constantly researching new technologies and better ways to solve problems using the power of computing. I hold a BSc (Hons) degree in Computer Science from Midlands State University. I am a husband of one woman and a father of two. I hope to share anything that I consider useful on this blog and I look forward to your comments.

Make a Free Website with Yola.