Loading Fonts

The Android API provides us with a class called Typeface that encapsulates a TrueType font. It provides a simple static method to load such a font file from the assets/ directory:

Typeface font = Typeface.createFromAsset(context.getAssets(), "font.ttf");

Interestingly enough, this method does not throw any kind of Exception if the font file can't be loaded. Instead a RuntimeException is thrown. Why no explicit exception is thrown for this method is a bit of a mystery to me.

0 0

Post a comment