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
BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Field with transparent background

Quote from the previous forum:


Guest
Field with transparent background
Posted: Jul 16, 2008 4:36 PM
 
How can we set the background color of a Field to transparent. So if its manager has a different color or a bitmap, it will show through.?
If not possible, how can we achieve similar effect?

Thanks


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/livelink.exe/fetch/2000/348583/800332/800505/800608/...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
jeffbacon
Posts: 17
Registered: ‎07-15-2008
My Device: Not Specified

Re: Field with transparent background

Theoretically, coudn't you just override the appropriate painting methods for the field whose background you want transparent and just not paint the background?
Jeff Bacon
http://about.me/jeffbacon
New Developer
Chouman82
Posts: 28
Registered: ‎07-21-2008
My Device: Not Specified

Re: Field with transparent background

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_ALL_WIDTH | HorizontalFieldManager.USE_ALL_HEIGHT){
           
            //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 

BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Field with transparent background

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.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Chouman82
Posts: 28
Registered: ‎07-21-2008
My Device: Not Specified

Re: Field with transparent background

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?
New Developer
Chouman82
Posts: 28
Registered: ‎07-21-2008
My Device: Not Specified

Re: Field with transparent background

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.

 

New Developer
Chouman82
Posts: 28
Registered: ‎07-21-2008
My Device: Not Specified

Re: Field with transparent background

never mind, i just realized my dumb mistake.   I should be using the VericalFieldManager.... duh!
BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Field with transparent background


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.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Chouman82
Posts: 28
Registered: ‎07-21-2008
My Device: Not Specified

Re: Field with transparent background

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. 

Developer
richard_puckett
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: Field with transparent background

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.  :smileyhappy: