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
Posts: 126
Registered: ‎06-09-2010
My Device: 9000
My Carrier: T Mobile
Accepted Solution

Create a colorful title bar

How can I create a title bar like ahead the Screen like Opera Mini or like Facebook ?
Developer
Posts: 132
Registered: ‎05-07-2009
My Device: Curve
My Carrier: Vodafone

Re: Create a colorful title bar

Use any manager say VerticalFieldManager.... add any custom field to the manager.... override tha paint method of the custom field..... and then use API method mainScreen.setTitle(Field field);

 

Here in field parameter.... give your manager object....

 

and you are done....

Sameer Joshi
Blackberry developer.
Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Create a colorful title bar

This is the custom class

 

package RssApplication;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;

public class CustomLabelField extends Field 
{
    private Bitmap image;
    private String label;
    private int foregroundColor;
    private int backgroundColor;

    public CustomLabelField(String label, int foregroundColor,int backgroundColor, Bitmap image, long style) 
    {
         super(style);
         this.label = label;
         this.foregroundColor = foregroundColor;
         this.backgroundColor = backgroundColor;
         this.image = image;
    }

    public CustomLabelField(String label, int foregroundColor,int backgroundColor, long style) 
    {
         super(style);
         this.label = label;
         this.foregroundColor = foregroundColor;
         this.backgroundColor = backgroundColor;
    }

    protected void layout(int width, int height) 
    {
         if ((getStyle() & Field.USE_ALL_WIDTH) == Field.USE_ALL_WIDTH) 
         {
              setExtent(width, Math.min(height, getPreferredHeight()));
         }
         else 
         {
              setExtent(getPreferredWidth(), getPreferredHeight());
         }
    }
      
    protected void paint(Graphics graphics) 
    {
         graphics.setBackgroundColor(backgroundColor);
         graphics.clear();
         graphics.setColor(foregroundColor);
         if (image != null) 
         {
              int textY = (getHeight() - getFont().getHeight()) / 2;
              int imageY = (getHeight() - image.getHeight()) / 2;
              graphics.drawBitmap(0, imageY, image.getWidth(), image.getHeight(),image, 0, 0);
              graphics.drawText(label, image.getWidth(), textY, DrawStyle.ELLIPSIS, getWidth()-image.getWidth());
         }
         else 
         {
              graphics.drawText(label, 0, 0, DrawStyle.ELLIPSIS, getWidth());
         }
    }

    public int getPreferredHeight() 
    {
         if (image != null) 
         {
               return Math.max(getFont().getHeight(), image.getHeight());
         }
         else 
         {
             return getFont().getHeight();
         }
    }

    public int getPreferredWidth() 
    {
         int width = getFont().getAdvance(label);
         if (image != null) 
         {
              width += image.getWidth();
         }
              return width;
    }       
}
 

 

 

And Use this class like this To paint the title Bar.

 

        CustomLabelField title;
        title=new CustomLabelField("Rss News Application",Color.WHITE, 0x999966, null, Field.USE_ALL_WIDTH);
        setTitle(title);

 ------------------------------------------------------------------------
Press Kudoes and Accept as solution Button, If u got Answer.

Thanks.

 

New Developer
Posts: 126
Registered: ‎06-09-2010
My Device: 9000
My Carrier: T Mobile

Re: Create a colorful title bar

Can you explain some details of paint method for Custom Field .I see operaMini has a 3D title bar.How to paint like 3D bar?
Regular Contributor
Posts: 55
Registered: ‎08-26-2010
My Device: 8520

Re: Create a colorful title bar

If you use the 4.6 api you can set the background of any component(Field) or container by calling the setBackground(Background back) method. You can use the classes from the net.rim.device.api.ui.decor to create a Background object with a simple Color or a variety of 4 colors. The Background object can also be created from a Bitmap. For creating Background objects look into the

BackgroundFactory class. After you make your Background object you can place it with the method setBackground(Background b)  from any Field object.

 

For example, a title bar with a blue background color:

 

public class App extends UiApplication{

 

...

public App(){

Background back = BackgroundFactory.createSolidBackground(Color.BLUE);

LabelField title = new LabelField(" TITLE ", LabelField.USE_ALL_WIDTH | LabelField.HCENTER);

title.setBackground(back);

MainScreen screen = new MainScreen();

screen.setTitle(title);

pushScreen(screen);

}

 

...

 

}

 

New Developer
Posts: 126
Registered: ‎06-09-2010
My Device: 9000
My Carrier: T Mobile

Re: Create a colorful title bar

I've known how to create a CustomLabelField but It's only the 2D labelField, you've seen the OperaMini Title bar? I wonder how they can do a title bar like that? Not simple a 2D labelField. Thanks all
New Developer
Posts: 126
Registered: ‎06-09-2010
My Device: 9000
My Carrier: T Mobile

Re: Create a colorful title bar

Anyone help?
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Create a colorful title bar

Use gradients with drawFilledPath() and some nice pictures as overlay.

New Developer
Posts: 126
Registered: ‎06-09-2010
My Device: 9000
My Carrier: T Mobile

Re: Create a colorful title bar

Kudo for you. Sorry, I'm a novice. What is gradient? How to use it
Highlighted
Developer
Posts: 132
Registered: ‎05-07-2009
My Device: Curve
My Carrier: Vodafone

Re: Create a colorful title bar

Have a look at the following link....

 

Gradient fill

 

It will clear your doubts...

Sameer Joshi
Blackberry developer.