How to easily add custom fonts (typeface) to your B4A android applications

ADVERTISEMENT

Today, I bring you another simple tutorial on how to add custom fonts easily to B4A android applications.

B4A is the fastest growing android applications development IDE out there. With a large community  of developers always available to attend to your needs.

A lot of people emailed me asking this questions. Now, why would you want to add custom fonts to your applications? N0te I will be using font and typeface interchangeably. Lets get stared.

WHY ADD CUSTOM FONTS TO YOUR ANDROID APPLICATIONS

Well, applications are not only about coding, the interface also matters. B4A currently has 3 typefaces that is SERIF, Monospace and Sans-Serif which is not enough. And typefaces like handwriting font or even your official corperate typeface can also make your UI beautiful.

Ways in Adding typeface

I will be highlighting on 3 ways but we will actually use two method.

You can add the typeface by Code.

To do this;

  1. click on File Manager in your IDE
  2. click on Add Files
  3. Navigate to where you have your fonts on your computer and add them
  4. Next Write this few lines of code to apply it to labels, edittext, or any other control you like.

 

'Declare font variables
Dim BerckerBlack As Typeface

'Declare variable to hold second typeface
Dim LatoRegular As Typeface

'Declare the variable to hold the third typeface
Dim Smoothie As Typeface

'Assign fonts to variables
BerckerBlack = Typeface.LoadFromAssets("BeckerBlackNF.ttf")
LatoRegular = Typeface.LoadFromAssets("Lato-Regular.ttf")
Smoothie = Typeface.LoadFromAssets ("Smoothie Shoppe.ttf")	

'Apply fonts (typeface) to a view
lblOne.Typeface = BerckerBlack
lblOther.Typeface = LatoRegular
lblSmo.Typeface = Smoothie

Looking a the Code Above, I added 3 files to my assets folder, i then declared a variable with type “TYPEFACE”

I loaded the fonts and assign it tot he variables.

Now the last thing left is just applying it to the controls. If you want to apply the typeface to all views at once, you can use this code below

'==APPLY TO ALL LABELS, EDITTEXTS, BUTTONS, CHECKBOXES, RADIOBUTTONS AND TOGGLEBUTTONS
For Each v As View In Activity.GetAllViewsRecursive
  If v Is Label Then
    Dim lbl As Label = v
    lbl.Typeface = LatoRegular
  End If
Next

 

Adding the typeface through the Wysiwyg Designer

To do this

  1. Click to open the WYSIWYG Designer to open
  2. click on add files – A dialog will open, choose the font you will like to include
  3. Select the View you will like to apply the font to
  4. click on the Typeface dropdown in the properties pane, your new fonts should be listed there
  5. Select it and apply. See image below

 

Finally the third method

Using a library

There is a library by NJDude in the b4a Forum. Download and add to your project.

Instructions are on this  PAGE HERE

DOWNLOAD SOURCE CODE [wpdm_package id=’5950′]

Congratulations. Remember to leave your comments below if you find any difficulties.

Related Posts

2 Responses

    1. You can download free fonts from websites like 1001fonts, squirrel fonts, etc. Google Fonts and you will get ton of response

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our Youtube Channel

Be informed when we upload new videos and source codes