Reputation: 1314
I'm developing my first BlackBerry application and I want to change the background to Black and all the text (in BasicEditField
labels, Label
s, etc) White.
I tried using setBackground(Background bg)
method on a VerticalFieldManager
, but it only blackened the screen as far as my components goes. That is, if I have only two buttons one below the other, the background is only Black as far as the end of buttons. So when there is less components on screen, the screen is half black and half white.
Is there any way I can achieve the behavior I want:
Any help greatly appreciated!
Upvotes: 1
Views: 1584
Reputation: 662
Signare's version works for older versions, but there is another option as of OS 4.6. Check out the classes in the net.rim.device.api.ui.decor package.
I'm using this to change the background of the screen on one of my programs:
public class MyScreen extends MainScreen {
MyScreen() {
Background screenColor = BackgroundFactory.createSolidBackground(Color.Black);
Manager backg= getMainManager();
backg.setBackground(screenColor);
EditField edit = new EditField("", "", 100, Field.FOCUSABLE){
protected void paint(Graphics g) {
g.setColor(Color.WHITE);
super.paint(g);
}
};
Background fieldColor = BackgroundFactory.createSolidBackground(Color.BLACK);
edit.setBackground(fieldColor);
backg.add(edit);
}
}
All of your fields have .setBackround()
and .setBorder()
methods, which let you make some nice customizations. I find this way easier than having to subclass all of my components just to change the background color. Unfortunately, you still have to do it to change the text color of an EditField
or LabelField
.
Upvotes: 2
Reputation: 4158
This code will set your background as black and editfield as white
VerticalFieldManager backg = new VerticalFieldManager(Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT){
public void paint(Graphics graphics) {
graphics.setBackgroundColor(Color.BLACK);
graphics.clear();
super.paint(graphics);
}
};
Now add editfield as
EditField edit= new EditField("", "", 100, Field.FOCUSABLE){
protected void paintBackground(Graphics g) {
g.setBackgroundColor(Color.WHITE);
g.clear();
}
backg.add(edit);
add(backg);
use g.setColor(Color.WHITE);
for changing the font color.
Upvotes: 4