The customization tag for customizing fonts is BLACKBERRY_CUSTOMIZATION_POINT_FONTS.
Use custom .ttf font files, which have a maximum size of 60KB, to install and use a custom font. You can set the default font for the Hybrid Web Container (described in step 1), or change the fonts for individual labels (described in step 2). Fonts for the list of Hybrid Apps are a special case (described in step 3).
String sCustomFontName = "MyCustomFont"; int iFontLoadCode = FontManager.getInstance().load( "FELIXTI.TTF", sCustomFontName, FontManager.APPLICATION_FONT); if( iFontLoadCode == FontManager.SUCCESS) { try { FontFamily oFamily = FontFamily.forName( sCustomFontName ); Font oFont = oFamily.getFont( Font.PLAIN, 23 ); FontManager.getInstance().setApplicationFont( oFont ); } catch (ClassNotFoundException e) { // the font was not found, so it cannot be set } } else { // error loading font }
import net.rim.device.api.ui.Font; import net.rim.device.api.ui.FontFamily;
try { FontFamily oFamily = FontFamily.forName( "MyCustomFont" ); Font oFont = oFamily.getFont( Font.PLAIN, 23 ); menu.setFont( oFont ); } catch ( ClassNotFoundException e ) { // problem finding the custom font String errormsg = e.getMessage(); }
import net.rim.device.api.ui.FontFamily; import net.rim.device.api.ui.component.Menu;
protected void makeMenu( Menu menu, int context ) { try { FontFamily oFamily = FontFamily.forName( "MyCustomFont" ); Font oFont = oFamily.getFont( Font.PLAIN, 23 ); menu.setFont( oFont ); } catch ( ClassNotFoundException e ) { String errormsg = e.getMessage(); System.out.println( errormsg ); } super.makeMenu( menu, context ); }
import net.rim.device.api.ui.FontFamily; import net.rim.device.api.ui.Font; import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.Font; import net.rim.device.api.ui.FontFamily;
public void setCustomFont( LabelField oLabel, String sCustomFontName, int iSize ) { try { FontFamily oFamily = FontFamily.forName( sCustomFontName ); Font oFont = oFamily.getFont( Font.PLAIN, iSize ); oLabel.setFont( oFont ); } catch (ClassNotFoundException e) { // the font was not found, so it cannot be set System.out.println( "Exception: font not found!" ); } }
LabelField oTitleLabel = new LabelField( Consts.APP_TITLE, DrawStyle.ELLIPSIS ); FontManager.getInstance().load( "SHOWG.TTF", "CustomTitleFont", FontManager.APPLICATION_FONT); setCustomFont( oTitleLabel, "CustomTitleFont", 23 ); this.setTitle( oTitleLabel );
// Draw text FontManager.getInstance().load( "HARLOWSI.TTF", "CustomHybridAppFont", FontManager.APPLICATION_FONT); try { FontFamily oFamily = FontFamily.forName( "CustomHybridAppFont" ); Font oFont = oFamily.getFont( Font.PLAIN, 23 ); graphics.setFont( oFont ); graphics.drawText( oApp.getDisplayName(), 2 * iMargin + iBitmap.getWidth(), y ); } catch ( ClassNotFoundException e ) { //can't load the font }