setStatus() in Blackberry

117 views Asked by At

I want to add a LabelField in the bottom and right of the screen in Blackberry. For setting the label at the bottom of the screen,

I used,

this.setStatus(lbl_version);

which gives the output perfectly fine, but, behind labelfield, the background image is not set. The label is set on white plain background. I want to set the label on the background image as well as bottom of the screen.

Please see following image URL and you will have better idea.

Thanks in advance. Please help me.

https://i.stack.imgur.com/5UKv6.png

2

There are 2 answers

0
Peter Strange On BEST ANSWER

I would add this as a comment to Nate's answer, but I don't have enough space, and I can't format the code in a comment.

I think Nate's solution works because he is using a solid colour and there is no Title or Banner area. I don't think it will work when using a bitmap or a gradient as the background and there is a title or banner.

To understand the answer you need to understand the Managers used in a MainScreen. As I understand it, there are a number of Managers used. One - the delegate Manager, is used for the whole screen. Added to this are:

  1. the banner Manager which is positioned at the top of the screen
  2. the title Manager which is positioned under the banner Manager
  3. the Main Manager, and
  4. the status Manager, which is positioned at the bottom of the screen.

The delegate Manager will provide background for all the other Managers, if they are transparent. My testing suggests that the background for the Managers for the Banner Field and Status Field are transparent. The background for the Manager for the Title Field is not - it is black - but changing it appears problematic.

Anyway, in my testing, to match the requirement, all you need to do is set the delegate Manager's background as required, and set the MainManager's background to transparent.

The following code is set up in a way that I think answers the question. However I have also left a number of commented out lines that I suggest you uncomment and note the effect. It is interesting (at least to a sad person like me).

Background transparentBackground = BackgroundFactory.createSolidTransparentBackground(0, 0);
Background gradientBackground = BackgroundFactory.createLinearGradientBackground(0X00909090, 0x00808080, 0x00E0E0E0, 0x00E8E8E8);
getMainManager().setBackground(transparentBackground);
getDelegate().setBackground(gradientBackground);
// this is the same as this.setBackground(gradientBackground);

LabelField banner = new LabelField("Hello Banner");
// banner.setBackground(gradientBackground);
setBanner(banner);

// LabelField title = new LabelField("Hello Title");
// title.setBackground(transparentBackground);
// setTitle(title);
// title.getManager().setBackground(transparentBackground);

LabelField status = new LabelField("Hello Status");
// status.setBackground(gradientBackground);
setStatus(status);

LabelField content = new LabelField("Hello Content", LabelField.FOCUSABLE);
content.setBackground(transparentBackground);
add(content);

// Following just added so that focus can be moved off the content LabelField
add(new NullField());

Finally, can I recommend this article for some interesting reading on MainScreen.
MainScreen explained

0
Nate On

First, make sure your LabelField has a transparent background, and then you should get to see whatever background has been set on the MainScreen containing it.

Second, I believe you'll need to set your (image) background on both the main screen itself, and its embedded "main manager", in order for the full screen to show the same background.

For example,

public class LabelScreen extends MainScreen {

   public LabelScreen() {
      super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);

      Background bg = BackgroundFactory.createSolidBackground(Color.GREEN);
      getMainManager().setBackground(bg);
      setBackground(bg);

      LabelField status = new LabelField("Hello Status");
      status.setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
      setStatus(status);
   }

}

Note: my example above uses a solid color background, but it should work the same way for an image background.