How to change Background of HorizontalFieldManager - blackberry

I want to set the Background of HorizontalFieldManager.
The sample code I've been searching is setting the background using Gradient for the main screen background.
//create gradient linear for background
this.getMainManager().setBackground(BackgroundFactory.createLinearGradientBackground(0x0099CCFF,
0x0099CCFF,0x00336699,0x00336699)
);
Then I try to use the same pattern to set background to HorizontalFieldManager, since it have this method. But it won't work. Here's the code
HorizontalFieldManager hManager = new HorizontalFieldManager();
Bitmap bitmapImage = null;
bitmapImage = Bitmap.getBitmapResource("img/home.png");
tabHome = new BitmapField(bitmapImage, BitmapField.FOCUSABLE
| BitmapField.HIGHLIGHT_FOCUS);
bitmapImage = Bitmap.getBitmapResource("img/in.png");
tabCheckInOut = new BitmapField(bitmapImage, BitmapField.FOCUSABLE
| BitmapField.HIGHLIGHT_FOCUS);
bitmapImage = Bitmap.getBitmapResource("img/barcode.png");
tabBarcode = new BitmapField(bitmapImage, BitmapField.FOCUSABLE
| BitmapField.HIGHLIGHT_FOCUS);
bitmapImage = Bitmap.getBitmapResource("img/options.png");
tabOptions = new BitmapField(bitmapImage, BitmapField.FOCUSABLE
| BitmapField.HIGHLIGHT_FOCUS);
tabHome.setFocusListener(this);
tabCheckInOut.setFocusListener(this);
tabBarcode.setFocusListener(this);
tabOptions.setFocusListener(this);
Background topBack = BackgroundFactory.createSolidBackground(0x00606A85);
hManager.setBackground(topBack);
hManager.add(tabHome);
hManager.add(tabCheckInOut);
hManager.add(tabBarcode);
hManager.add(tabOptions);
add(hManager);
I'm using HorizontalFieldManager and add 4 BitmapField, then I using BackgroundFactory to create solidBackground, and set it to the manager
but when I run it, the background color does not apply. The gradient example work well. Is there anything that I'm missing? Please help me.
Thanks

After doing some deep web search. Here's the answer guys
HorizontalFieldManager manager = new HorizontalFieldManager()
{
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(0x000000FF);//blue
graphics.clear();
super.paint(graphics);
}
};
UPDATE:
You must only use Web Color
such as 0x006699FF should work
but 0x00606A85 would not work.
if you want a specific color, i recommend you using bitmap.
UPDATE:
Another solution
HorizontalFieldManager manager = new HorizontalFieldManager(Field.USE_ALL_WIDTH);
manager.setBackground(BackgroundFactory.BackgroundFactory
.createSolidBackground(0x00cccccc));

Related

how to set layout background image in blackberry

I am trying to set VerticalFieldManager background image. here is my code hope it would help you to find problem.
my problem is
1) background image is appear but not get full height of the image.
VerticalFieldManager verFM = new VerticalFieldManager(USE_ALL_WIDTH );
Bitmap bt = Bitmap.getBitmapResource("top_bar#2x.png");
BitmapField btm = new BitmapField(bt);
btm.getPreferredHeight();
verFM.add(btm);
VerticalFieldManager VFM = new VerticalFieldManager( USE_ALL_HEIGHT);
VFM.setMargin(5, 5, 10, 40);
VFM.setPadding(5, 5, 60, 10);
System.out.println();
Bitmap bitmap = Bitmap.getBitmapResource("registration_form_bg#2x.png");
Background bgg = BackgroundFactory.createBitmapBackground(bitmap,Background.POSITION_X_LEFT, Background.POSITION_Y_TOP,Background.REPEAT_SCALE_TO_FIT);
VFM.setBackground(bgg);
verFM.add(VFM);
add(verFM);

Blackberry background image?

I have searched but haven't find out any solution, i have but its creating problems. when I insert this it says illegal argument and doesn't start.
Bitmap bitmap = Bitmap.getBitmapResource("Background.png");
this.getMainManager().setBackground(
BackgroundFactory.createBitmapBackground(bitmap)
);
It doesn't work.
Thanks for helping! Its working. Just a typo error of my path
tyy this -
final Bitmap top = Bitmap.getBitmapResource("your background image.png");
final VerticalFieldManager top_ = new VerticalFieldManager(Manager.NO_HORIZONTAL_SCROLL | Manager.NO_HORIZONTAL_SCROLLBAR | Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR | Field.USE_ALL_WIDTH){
public void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, top.getWidth(),
top.getHeight(), top, 0, 0);
super.paint(graphics);
}
};
Now you add all your fields to this top_. then add the top_ to your screen. If there is no fields, it will not display the background image. so Dont forget to add some fields.

how to set an image as background in blackberry

I was able to add the background only to the fields that were added in the screen with the below code:
VerticalFieldManager manager = new VerticalFieldManager();
Bitmap image = Bitmap.getBitmapResource("Penguins.jpg");
Background bg = BackgroundFactory.createBitmapBackground(image);
manager.setBackground(bg);
manager.add(new LabelField("HEll"));
add(manager);</code>
the output screen is like below:
How will get the image filled with whole screen, with the fields visible on top of it. Thank you
Bitmap background = Bitmap.getBitmapResource("background.png");
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH) {
public void paint(Graphics g) {
g.drawBitmap(0, 0, "Device Width", "Device Height",
background, 0, 0);
super.paint(g);
}
};
vfm.add(new LabelField("HEll"));
add(vfm);
You can also use this code to set the background image in Blackberry, But this works only 5.0 or above.
Background bg = BackgroundFactory.createBitmapBackground(Bitmap bitmap);
// OR
Background bg = BackgroundFactory.createBitmapBackground(Bitmap bitmap, int positionX, int positionY, int repeat);
this.getMainManager().setBackground(bg);

What is the easiest way to set background image of the application on Blackberry

I know, this question was asked before. However I can't beleive that this operation is so difficult. I think i miss some important points on developing Blackberry applications.
Try to use the following code:
Bitmap backgroundBitmap = Bitmap.getBitmapResource("background.png");
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 super.paint
//to paint the rest of the screen.
graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(),
backgroundBitmap, 0, 0);
super.paint(graphics);
}
};

BlackBerry - How to show the system status bar on top of the application screen

My question is rather simple, but I couldn't find an answer, could be because I'm using the wrong terms, but let me try: is there a way for a BlackBerry application (extending the regular Screen component) to keep the status bar visible (by status bar, to clarify, I mean the area where you see the battery strength, network name, signal strength, etc.)?
thank you
There is as yet (in my experience up to OS version 4.6) no API exposed to do this, strange as that is. You may of course program your own status bar, as many applications do, if you feel it necessary. But you have to gather the information and display the status information with logic coded into your own program.
Here's some sample code. First, for a nice title bar, look here: http://www.naviina.eu/wp/blackberry/iphone-style-field-for-blackberry/
To display a battery strength image:
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.DeviceInfo;
...
public static Bitmap getBatteryImage(){
int batteryPercent = DeviceInfo.getBatteryLevel();
int val = 1;
if(batteryPercent > 80){
val = 5;
}else if(batteryPercent > 60 ){
val = 4;
}else if(batteryPercent > 40){
val = 3;
}else if(batteryPercent > 20){
val = 2;
}else {
val = 1;
}
Bitmap batteryImage = Bitmap.getBitmapResource("mybattery"+val+".png");
return batteryImage;
}
...
You need to create images mybattery1.png to mybattery5.png, and place them in your src folder. A good size to start with is 28x11 pixels (GIMP is a good free image editor). If you used the title bar code from Naviina.eu, then insert the following code in the paint method, like so:
protected void paint(Graphics graphics) {
...
int w = this.getPreferredWidth();
int h = this.getPreferredHeight();
Bitmap batteryImage = getBatteryImage();
int batteryStartY = (h - batteryImage.getHeight()) / 2;
graphics.drawBitmap(w - batteryImage.getWidth(), batteryStartY, w, h,
batteryImage, 0, 0);
...
}
Some things to note: the image(s) do not refresh unless you invalidate the screen or push/pop to another screen. Also, you may want smaller images for a Pearl vs. a Curve or Storm.
You could use the StandardTitleBar, it might be a bit more straightforward.
http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/ui/component/StandardTitleBar.html
There are actually three places you can insert your status information in a MainScreen subclass:
Banner area - is located at the top
of the screen
Title area - is below the Banner area and normally has a different background
Status area - at the bottom of the screen
You use setBanner(Field), setTitle(Field) and setStatus(Field) to display information as shown as follows:
HorizontalFieldManager hfm = new HorizontalFieldManager();
EncodedImage logo = EncodedImage.getEncodedImageResource("img/Logo.png");
Bitmap bm = logo.getBitmap();
hfm.add(new BitmapField(bm));
hfm.add(new LabelField("Banner area"));
setBanner(hfm);
setTitle(new LabelField("Title area", LabelField.FIELD_HCENTER));
setStatus(new LabelField("Status area", LabelField.FIELD_HCENTER));
The advantage is that each method accepts a Field as an argument and the programmer can compose a complex Field with managers.

Resources