jkramer
jkramer

Reputation: 15758

How can I add an icon to the title bar of a BlackBerry app?

I'm writing a BlackBerry app in Java using the BlackBerry Java API (OS 4.7 and above). I would like to add an icon to the title row of my app. The API documentation says that the method "setTitle" of the "MainScreen" class takes a "Field", so I thought I could just create a "HorizontalFieldManager" that contains an icon (BitmapField) and some text (LabelField). However when I do that I get a weird exception. Is it possible at all to use any field (other than LabelField) for setTitle()?. I've seen that other apps have icons in their title row, but maybe they're not using setTitle() but create their own (fake) title row.

Upvotes: 1

Views: 1309

Answers (1)

jkramer
jkramer

Reputation: 15758

I already solved it. I don't know what I did wrong previously, but this is how it works as I described it in the initial question:

HorizontalFieldManager manager = new HorizontalFieldManager();
BitmapField bitmap = new BitmapField(PNGEncodedImage.getEncodedImageResource("icon.png").getBitmap());
LabelField label = new LabelField(text);

manager.add(bitmap);
manager.add(label);

setTitle(manager);

Upvotes: 5

Related Questions