05-19-2009 04:20 PM
Usually, the background color of title is black and the other area in the main screen is white. I want to set the title background color to blue or some thing like Linear Gradient Background. I try the following two ways, but there is always a black line at the bottom of the title bar.
Background background = BackgroundFactory .createLinearGradientBackground(0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00); LabelField title = new LabelField("Hello World Demo", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); title.setBackground(background); setTitle(title);
LabelField title = new LabelField("Hello World Demo", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); HorizontalFieldManager hrzManager = new HorizontalFieldManager() { protected void paintBackground(Graphics graphics) { graphics.setBackgroundColor(0x00382B79); graphics.clear(); super.paint(graphics); } }; hrzManager.add(title); setTitle(hrzManager);
Solved! Go to Solution.
05-20-2009 01:47 AM - edited 05-20-2009 01:52 AM
Hi,
I think there may be some problem in using default setTilte() method.
It have someting default behaviour with the device.
There maybe some way to customize the default title for removing the black line at the bottom of the title bar.
But i can suggest you some alternative that will behave like the titleBar without using setTitle() method.
You can use something like below to achieve your requirement.
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
class TestScreen extends MainScreen{
private VerticalFieldManager verticalManager;
private HorizontalFieldManager hrzManager;
TestScreen()
{
super(NO_VERTICAL_SCROLL);
LabelField title = new LabelField("Hello World Demo",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
hrzManager = new HorizontalFieldManager()
{
protected void paintBackground(Graphics graphics)
{
graphics.setBackgroundColor(0x00382B79);
graphics.clear();
super.paint(graphics);
}
};
hrzManager.add(title);
this.add(hrzManager);
//rather than adding component in the mainScreen
//add components in this verticalManager and then
// add this manager to mainScreen
verticalManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR)
{/*
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(0x00ffffff);
graphics.clear();
super.paint(graphics);
}*/
protected void sublayout( int maxWidth, int maxHeight )
{
int width = Display.getWidth();
int height = Display.getHeight() - hrzManager.getHeight();
super.sublayout( width, height);
setExtent( width, height);
}
};
ButtonField button1 = new ButtonField("Button1");
ButtonField button2 = new ButtonField("Button2");
ButtonField button3 = new ButtonField("Button3");
ButtonField button4 = new ButtonField("Button4");
ButtonField button5 = new ButtonField("Button5");
verticalManager.add(button1);
verticalManager.add(button2);
verticalManager.add(button3);
verticalManager.add(button4);
verticalManager.add(button5);
this.add(verticalManager);
}
}
Regards
Bikas
05-20-2009 10:12 AM
05-10-2011 05:21 AM
Thank you Bikas for this trick.
I found that you don't eventually need the horizontal field for the title. The title will be handled by the default vertical field manager of Mainscreen, then.
Kudos added...
04-09-2012 03:20 PM
Hello,
I'd really like to learn to be able to do this because the white background is hurting my eyes and head, especially when I've been using my laptop a lot. However, I have no idea where to write that information and I'm a bit of a novice! Could you offer me any further help please?
My Blackberry is a Torch 9800.
Many thanks in advance,
Beth
04-09-2012 03:30 PM
This behavior of setTitle() has been explained here:
If you want more control, use setBanner() rather than setTitle() (also suggested in the knowledge base article above).