The android platform already comes with the following predefined fonts: “sans”,”serif” and “monospace”. The android platform allows us to add and use new fonts within the application we develop. In order to use a specific font we just need to reference it within the XML layout document. Adding the android:typeface attribute into the view XML element and specify the font name as its value does the trick. The following sample shows how to specify the usage of the “serif” font in a specific text view.
The simplest way to use a new font in our application is adding the required TTF font file to the assets folder of our application and loading it in our code. The following code sample uses the Ansshenkin.ttf free hebrew font you can download at http://fonti.come2us.co.il/fonts.htm.
The following code samples creates a new TypeFace object that represents the Ansshenkin font. Placing the Ansshenkin.ttf file within the application assets folder we can easily load it into our code and create a new TypeFace object based on its data. The TypeFace.createFromAsset() static method loads the Ansshenkin.ttf file from the assets folder and creates a new TypeFace object based on the data that file includes.
The text this application shows was saved separatedly within the strings.xml resource file.
The following screenshot was taken when running this application. The displayed text is the hebrew word for peace.
Press here to download the files of this application.