Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
txj78
Posts: 32
Registered: ‎05-19-2009
My Device: Not Specified
Accepted Solution

How to set background color of title?

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);

 

 

Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to set background color of title?

[ Edited ]

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

 

 

 

 

 

Message Edited by bikas on 05-20-2009 11:52 AM
New Developer
txj78
Posts: 32
Registered: ‎05-19-2009
My Device: Not Specified

Re: How to set background color of title?

Thank you Bikas. It works.
Developer
Utel
Posts: 31
Registered: ‎04-13-2011
My Device: BlackBerry Torch 9800

Re: How to set background color of title?

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...

New Member
bertiebumpster
Posts: 1
Registered: ‎04-09-2012
My Device: Blackberry Torch 9800 RDG71UW

Re: How to set background color of title?

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

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: How to set background color of title?

This behavior of setTitle() has been explained here:

MainScreen explained

If you want more control, use setBanner() rather than setTitle() (also suggested in the knowledge base article above).

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!