I am trying to create a LabelField with no background at all, as a transparent one. I have a background set to my screen with a bitmap and I would like to have my LabelField transparent.
I have the following code but it does not work.
BitmapField info;
EncodedImage logoBitmap = EncodedImage.getEncodedImageResource("userInfo.png");
info = new BitmapField(null, Field.FIELD_LEFT |Field.FIELD_BOTTOM);
info.setImage(logoBitmap);
AbsoluteFieldManager superMainContainer;
superMainContainer.add(info,0,200);
LabelField nameLabel = new LabelField("Name:");
nameLabel.setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
superMainContainer.add(nameLabel, 10, 210);
[Updated]
Following code snippet is working on my simulator. Difference between the following one and your code is only some initialization code.
Bitmap bm = Bitmap.getBitmapResource("image.png");
BitmapField info = new BitmapField(bm, Field.FIELD_LEFT
| Field.FIELD_BOTTOM);
LabelField lbl = new LabelField("LabelField Text");
lbl.setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
AbsoluteFieldManager superMainContainer = new AbsoluteFieldManager();
superMainContainer.add(info, 0, 200);
superMainContainer.add(lbl, 10, 210);
MainScreen screen = new MainScreen();
screen.add(superMainContainer);
UiApplication.getUiApplication().pushScreen(screen);
[Old]
LabelField lbl;
lbl.setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
You didn't initialize the LabelField - nameLabel before applying Background.
And you don't need to set any Background instance for getting a transparent background, the default LabelField will work for this case.
Related
I'm developing a BlackBerry Native Application BB SDK 5.0.
I want the Ui of this format.
--text-- --Hyperlink-- --text--
and so on.
This means i can have hyperlinks in-between the sentences.
So when i tried to make this, i'm facing some alignment issues.
Word wrap occurs and this leaves a large white space in right side of the screen.
To simulate i have attached a prototype of my code.
LabelField mylabel1 = new LabelField("Label 11231 23123123",LabelField.FIELD_LEFT);
LabelField mylabel2 = new LabelField("Label2",LabelField.FIELD_RIGHT);
LabelField mylabel3 = new LabelField("Label 312312 3123",LabelField.FIELD_RIGHT);
LabelField mylabel4 = new LabelField("Label 41312 3123",LabelField.FIELD_RIGHT);
LabelField mylabel5 = new LabelField("Label5",LabelField.FIELD_RIGHT);
LabelField mylabel6 = new LabelField("Label6",LabelField.FIELD_RIGHT);
LabelField mylabel7 = new LabelField("Label7",LabelField.FIELD_RIGHT);
LabelField mylabel8 = new LabelField("Label8",LabelField.FIELD_RIGHT);
FlowFieldManager hr=new FlowFieldManager(FlowFieldManager.USE_ALL_WIDTH);
hr.add(mylabel1);
hr.add(mylabel2);
hr.add(mylabel3);
hr.add(mylabel4);
hr.add(mylabel5);
hr.add(mylabel6);
hr.add(mylabel7);
hr.add(mylabel8);
add(hr);
I added HorizontalFieldManager to screen with backgroundcolor and with specific width and height.And i added a labelField to hfm.But labelfield displaying at top in hfm.How can i adjust it to center.
Try This
LabelField.setMargin(Hfm height/2, 15, 0, 15);
Did you try to set the style of the labelfield to LabelField.Field_HCENTER? This should work for you
I keep getting an IllegalArgumentException and nothing shows on the BlackBerry simulator when I run this code. What could be wrong with it?
public MyScreen()
{
// Set the displayed title of the screen and add the weather icons
setTitle("PixWeather");
cityField = new LabelField("Queensland", Field.FIELD_LEFT);
tempField = new LabelField("17", Field.FIELD_RIGHT);
condField = new LabelField("sunny",Field.FIELD_RIGHT);
weather_icon = Bitmap.getBitmapResource("sun_icon.png");
bitmapField = new BitmapField(weather_icon, Field.FIELD_LEFT);
VerticalFieldManager vfield = new VerticalFieldManager();
HorizontalFieldManager hfield1 = new HorizontalFieldManager();
hfield1.add(cityField);
hfield1.add(tempField);
HorizontalFieldManager hfield2 = new HorizontalFieldManager();
hfield2.add(bitmapField);
hfield2.add(condField);
vfield.add(hfield1);
vfield.add(hfield2);
}
The IllegalArgumentException could be unrelated, but nothing is showing up on your screen because you didn't add anything to your screen.
You need to add the vfield to the screen itself. Add the following line:
add(vfield);
I'm just learing how to program the blackberry and trying to display a bitmap on the screen, here is the code:
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle2");
LabelField lb = new LabelField("hello ted2");
add(lb);
Bitmap logoBitmap = Bitmap.getBitmapResource("res/icon2.png");
BitmapField fd= new BitmapField(logoBitmap, Field.FIELD_HCENTER);
add(fd);
}
The label is drawn but not the bitmap.
Your path is wrong, copy the image into /res/img. To retrieve that, use the file name only.
Bitmap logoBitmap = Bitmap.getBitmapResource("icon2.png");
I think you need to put the two fields into a VerticalFieldManager:
public MyScreen()
{
VerticalFieldManager vfm = new VerticalFieldManager();
// Set the displayed title of the screen
setTitle("MyTitle2");
LabelField lb = new LabelField("hello ted2");
vfm.add(lb);
Bitmap logoBitmap = Bitmap.getBitmapResource("res/icon2.png");
BitmapField fd= new BitmapField(logoBitmap);
vfm.add(fd);
add(vfm);
}
Horizontally, I want to display two bitmaps, and between them display a label field.
The code seems straightforward, but all the fields are added on the left side of the screen.
HorizontalFieldManager hfm = new HorizontalFieldManager();
callbmp = new BitmapField(ei.getBitmap(),Field.FOCUSABLE |BitmapField.FIELD_LEFT);
LabelField NAME = new LabelField("mylable", LabelField.FIELD_HCENTER);
mailbmp = new BitmapField(mail.getBitmap(),Field.FOCUSABLE|BitmapField.FIELD_RIGHT);
hfm.add(callbmp);
hfm.add(NAME);
hfm.add(mailbmp);
add(hfm);
Manager customManager = new Manager(0)
{
protected void sublayout(int width, int height) {
setPositionChild(
getField(0),
0,
0);
layoutChild(
getField(0),
getField(0).getPreferredWidth(),
getField(0).getPreferredHeight());
setPositionChild(
getField(1),
Graphics.getScreenWidth()/2 - getField(1).getPreferredWidth()/2,
0);
layoutChild(
getField(1),
getField(1).getPreferredWidth(),
getField(1).getPreferredHeight());
setPositionChild(
getField(2),
Graphics.getScreenWidth() - getField(2).getPreferredWidth(),
0);
layoutChild(
getField(2),
getField(2).getPreferredWidth(),
getField(2).getPreferredHeight());
setExtent(width, height);
}
};
customManager.add(new BitmapField(Bitmap.getBitmapResource("image1.png")));
customManager.add(new LabelField("Hello Alignment"));
customManager.add(new BitmapField(Bitmap.getBitmapResource("image2.png")));
HorizontalFieldManager lays out the fields left-to-right in the order in which they are added. The style bits for horizontal layout are ignored.
If you want left, right and center on a horizontal line, you'll need a custom manager.
This should be your requirement:
It can be done simply by subtracting the widths of the items you are adding on your horizontal field manager. By default the leftButton or the first item you add on the HFM will be added on left. Then you can add your label(userName) and the rightButton in the following way:
LabelField userName = new LabelField("MaheshBabu");
HorizontalFieldManager horizontalBar = new HorizontalFieldManager(USE_ALL_WIDTH|Manager.NO_HORIZONTAL_SCROLL|Manager.NO_HORIZONTAL_SCROLLBAR);
horizontalBar.setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
rightButton.setMargin(0, 0, 0, Display.getWidth()-rightButton.getPreferredWidth()-leftButton.getPreferredWidth()-userName.getPreferredWidth());
horizontalBar.add(leftButton);
horizontalBar.add(userName);
horizontalBar.add(rightButton);