Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
Posts: 236
Registered: ‎07-28-2010
My Device: Not Specified
My Carrier: Software Developer

Problem in loading custom font from .ttf file in blackberry application

Hi All,

            I am developing an bb application in that i am loading .ttf file to implement  custom Font for my application, but the problem is first time when my application will start the custom Font is applying for my application but second and third time it is not applying custom Font.

 

my code is as following -

 

if

(FontManager.getInstance().load("Alcohole.ttf", "MyFont",

FontManager.

APPLICATION_FONT) == FontManager.SUCCESS) {

 

try{

FontFamily typeface = FontFamily.forName(

"MyFont");

Font myFont = typeface.getFont(Font.

PLAIN, 20);

FontManager.getInstance().setApplicationFont(myFont);

}

catch(ClassNotFoundException e) {

System.

out.println(e.getMessage());

}

}

 

 

 

Thanks To All. 

Developer
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10
My Carrier: Aircel

Re: Problem in loading custom font from .ttf file in blackberry application

Try this one may be it will help you.

 

public Font fontStyle(int style, int size)
	{
		FontFamily fontFamily;
		try
		{
			fontFamily=FontFamily.forName("Alcohole");
		}
		catch(ClassNotFoundException e1)
		{
			fontFamily=Font.getDefault().getFontFamily();
		}
		Font font=fontFamily.getFont(style, size);
		return font;
	}

 

Highlighted
Contributor
Posts: 14
Registered: ‎09-20-2011
My Device: Developer
My Carrier: Vodafone

Re: Problem in loading custom font from .ttf file in blackberry application

Hi maanbhati,

 

Try to unload the font when closing your application.

 

FontManager.getInstance().unload("MyFont");