Custom Fonts in Blackberry Application

Download the .ttf (True Type Font)file and include it in src folder.

Include this code into the constructor.

EditField edField1 = new EditField (“”, “TestEditField”, 30, EditField.READONLY| EditField.FIELD_VCENTER){
protected void layout(int width, int height)
{
super.layout(customWidth, customHeight);
setExtent(customWidth, customHeight);
}
};

Font fo3 = loadCustomFonts(“digital-7.ttf”, “ThirdFont”, 0, 40);
edField1.setFont(fo3);

 

Include this function.

public Font loadCustomFonts (String path, String fontname,int fontStyle, int fontSize){
InputStream stream = this.getClass().getResourceAsStream(path);
if (FontManager.getInstance().load(stream, fontname,                 FontManager.APPLICATION_FONT) == FontManager.SUCCESS){
try{
FontFamily family;
add(new LabelField(“”));
family = FontFamily.forName(fontname);
Font myFont = family.getFont(fontStyle,fontSize);
return myFont;
}
catch (ClassNotFoundException e){System.out.println(e.getMessage());}
}
else {
try{
FontFamily family;
add(new LabelField(“”));
family = FontFamily.forName(fontname);
Font myFont = family.getFont(fontStyle,fontSize);
return myFont;
}
catch (ClassNotFoundException e){System.out.println(e.getMessage());}
}
return null;
}

By Using this we can add custom font into our Application.

thank you.


Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at info@nanostuffs.com, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box