07-17-2008 11:24 AM
Quote from the previous forum:
What type of field are you referring to? Text based fields should be transparent by default.
If you are using a background image, using a PNG image with a transparent backround should work. The link below contains an example.
How To - Use a background image in application screens
Article Number: DB-00498
http://www.blackberry.com/knowledgecenterpublic/li
07-17-2008 07:17 PM
07-22-2008 03:59 PM
Hey Mark,
Quick question regarding the sample code.
public BackgroundImage()
{
//The background image.
backgroundBitmap = Bitmap.getBitmapResource("background.png");
MainScreen mainScreen = new MainScreen();
HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_
//Override the paint method to draw the background image.
public void paint(Graphics graphics)
{
//Draw the background image and then call paint.
graphics.drawBitmap(0, 0, 240, 240, backgroundBitmap, 0, 0);
super.paint(graphics);
}
};
//The LabelField will show up through the transparent image.
LabelField labelField = new LabelField("This is a label");
//A bitmap field with a transparent image.
//The background image will show up through the transparent BitMapField image.
BitmapField bitmapField = new BitmapField(Bitmap.getBitmapResource("field.png"))
//Add the manager to the screen.
mainScreen.add(horizontalFieldManager);
//Add the fields to the manager.
horizontalFieldManager.add(labelField);
horizontalFieldManager.add(bitmapField);
//Push the screen.
pushScreen(mainScreen);
}
Do we have to add a new fieldmanager and override its paint method? can we not just override the paint method of the mainscreen? why or why not?
Thanks,
Howard
07-22-2008 05:13 PM
MainScreen's paint method that it inherits from the Screen class is painted under the paint method of the VerticalFieldManager used within MainScreen.
Overriding the paint method of a manager you add to the screen ensures that your image is visible behind fields added to it.
07-22-2008 05:17 PM
07-22-2008 07:00 PM
I am not sure if i am doing something wrong but I am not able to add RichTextField or LabelField on top of my background image.
public class MenuScreen extends MainScreen { private HorizontalFieldManager hfm; public MenuScreen() { hfm = new HorizontalFieldManager(HorizontalFieldManager.USE_
ALL_WIDTH|HorizontalFieldManager.USE_ALL_HEIGHT){ public void paint(Graphics graphics) { Bitmap bgImage = Bitmap.getBitmapResource(BG_IMAGE_PATH); graphics.drawBitmap(0,0,Display.getWidth(), Display.getHeight(), bgImage, 0, 0); super.paint(graphics); }; this.add(hfm); Bitmap bitmap = Bitmap.getBitmapResource("HEADER.png"); bitmapField = new BitmapField(bitmap, BitmapField.NON_FOCUSABLE); hfm.add(bitmapField); htm.add(new LabelField("This is a label")); htm.add(new RichTextField("HEEEEELLLLLO")); } }
The bitmap(HEADER) showed up on the top of the screen fine, but the label field and the richtextfield doesn't show up at all. Not sure what is going on.
07-22-2008 09:38 PM
07-23-2008 10:07 AM
Chouman82 wrote:
so if i want to have a background image, i should always add a manager to the screen. Override the paint method of the manager and add all fields to the manager?
This is correct when using FullScreen or MainScreen, which have a VerticalFieldManager built into it.
If you are creating a custom screen derrived from the Screen class, you can override paint in its delegate manager since you are creating the instance of the manager it uses.
07-23-2008 05:36 PM
When i create a new VericalFieldManager with the flag VerticalFieldManager.USE_ALL_HEIGHT, then i do a Display.getContentHeight(). It returns 1073741823
What can i do so that the Background Image will only take up the size of the screen and not over.
07-23-2008 06:43 PM
Make your background image the same height as the screen. If you're targeting multiple devices you may need to produce multiple builds, each including graphics appropriate for the target device. If your background is a pattern that can be tiled then you'd just paint it out until you've covered either your screen height or your content height (whichever is greater).
As you saw, the USE_ALL_HEIGHT parameter is really only useful when your manager is contained in some more-constrained space. ![]()