If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
Developer
JasonBourne
Posts: 91
Registered: ‎04-17-2009
My Device: Blackberry Curve 8320
Accepted Solution

How to set Image in Title of The Screen

Hi i am new to BlackBerry Forum

 

I want to set my Screen Title as Image with Background.

 

how to write this? 

have to use CustomeField ?

Thanks in Advance.

 

Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: How to set Image in Title of The Screen

Hi,

 

You can use setTitle() with bitmapfield as its parameter.

 

It will set image as title of your screen.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.
Developer
simon_hain
Posts: 15,908
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to set Image in Title of The Screen

setTitle also accept managers of all kinds.
you can create a HorizontalFieldManager, add a bitmap and some text, for example.
Or create your own custom Field.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
JasonBourne
Posts: 91
Registered: ‎04-17-2009
My Device: Blackberry Curve 8320

Re: How to set Image in Title of The Screen

Thanks for ur Reply's

 

 

please give some sample Code.

using Horizontal Field Manager.

One more  my problem is i have to set Background Color with Image in Title Screen.

 

please help me

 

 :smileysad:

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to set Image in Title of The Screen

Hi JasonBourne,

 

You may also use BitmapField with background color and the title image overriding paint.

and using this BitmapField as setTitle

 

But the problem of using setTitle method is the border color that you cannot remove (i think).

 

 

This is why , I have written a CustomTitleBar class where

* background color is black

* title image is placed horizontal center

* title bar height is same as the height of the title image

 

Here is my TitleBar class:

 

 

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
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.*;


/**
* customized Title Bar
* background color is black (BACKGROUND_COLOR)
* image is placed horizontal center (titleImage)
* title bar height is same as the height of the title image (fieldHeight)
*/
public class TitleBar extends Field implements DrawStyle
{
private int fieldWidth;
private int fieldHeight;
private int fontColour;
private int backgroundColor;

private Bitmap titleImage = Bitmap.getBitmapResource("topBannerTransparent.png");
private static final int BACKGROUND_COLOR = 0x00000000;


public TitleBar()
{
super(Field.NON_FOCUSABLE);
fieldHeight = titleImage.getHeight();
fieldWidth = Graphics.getScreenWidth();

//background color is black
backgroundColor = BACKGROUND_COLOR;
}

public void setBackgroundColour(int _backgroundColour)
{
backgroundColor = _backgroundColour;
invalidate();
}

protected void layout(int width, int height)
{
setExtent(getPreferredWidth(), getPreferredHeight());
}

public int getPreferredWidth()
{
return fieldWidth;
}

public int getPreferredHeight()
{
return fieldHeight;
}

protected void paint(Graphics graphics)
{

int w = this.getPreferredWidth();
int h = this.getPreferredHeight();

graphics.setColor(backgroundColor);
graphics.fillRect(0, 0, w, h);

int marginX = (w- titleImage.getWidth() ) / 2 ;
graphics.drawBitmap(marginX, 0, w, h, titleImage, 0, 0);
}
}

 

 

And one more thing, to make this TitleBar treat like original title bar( always visible in the top) you must have to use this like below:

 

 

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.Graphics;
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 TitleBarExampleScreen extends MainScreen
{
TitleBar titleBar = new TitleBar();
int titleBarHeight = titleBar.getPreferredHeight();

public TitleBarExampleScreen()
{

super(NO_VERTICAL_SCROLL);

//title Bar added here
this.add(titleBar);


VerticalFieldManager verticalManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR )
{
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(0x00000000);
graphics.clear();
super.paint(graphics);
}
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight() - titleBarHeight;

super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};

//now add everything in the verticalManager
verticalManager.add(new LabelField("Test Label"));
verticalManager.add(new ButtonField("Test Button"));

//and at last add verticalManager in scereen
this.add(verticalManager);
}
}

 

Hope this might help you.

 

 

Regards

Bikas

 

 

 

Please use plain text.
Developer
dpdragnev
Posts: 39
Registered: ‎04-30-2009
My Device: Not Specified

Re: How to set Image in Title of The Screen

Hi bikas,

 

First, thank you for the great example. I tried it and it works great except for one detail: when I add fields to the VerticalFieldManager, they do not appear on the screen. Basically, I get the titleBar setup, I was able to paint the background of the VerticalFieldManager, I was also able to draw a Bitmap as a background fot the Manager, but when I add Fields to it, nothing happens. I see the titleBar and the background, but no fields.

 

I wonder if I missed anything...  I am using the following code:

 

public class BBTESTScreen2 extends MainScreen { TitleBar bar = new TitleBar("Test Application"); int barHeight = bar.getPreferredHeight(); int bgColor = 0xb9aaf9; //constructor public BBTESTScreen2() { super(NO_VERTICAL_SCROLL); this.add(bar); //the content VerticalFieldManager content = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR) { private Bitmap bgImage = Bitmap.getBitmapResource("bb-bg.png"); public void paint(Graphics g) { //g.setBackgroundColor(bgColor); //g.clear(); //super.paint(g); int yPos = 0; int xPos = 0; int w = Display.getWidth(); int h = Display.getHeight() - bar.getHeight(); g.drawBitmap(xPos, yPos, w, h, bgImage, 0, 0); } protected void sublayout(int maxW, int maxH) { int w = Display.getWidth(); int h = Display.getHeight() - barHeight; setExtent(w, h); } }; //add the screen's fields to content content.add(new LabelField("Test 1")); content.add(new LabelField("Test 2")); this.add(content); } //constructor } //class

 

 

Please let me know if you see anything that I am doing wrong.

 

Thanks,

 

Daniel D.

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to set Image in Title of The Screen

Hi Daniel, 

 

1. Add the line at the end of your paint()  method:

     super.paint(g);

 

2. Add the line in your sublayout() method:

      super.sublayout( w,h);

    before the line setExtent(w, h);

 

 

Regards

Bikas

Please use plain text.
Developer
dpdragnev
Posts: 39
Registered: ‎04-30-2009
My Device: Not Specified

Re: How to set Image in Title of The Screen

Hi Bikas,

 

Thank you very much for your help. Your suggestion fixed the problem.

 

Daniel

Please use plain text.
Developer
JasonBourne
Posts: 91
Registered: ‎04-17-2009
My Device: Blackberry Curve 8320

Re: How to set Image in Title of The Screen

Hi guys,

 

Thanks for all your supports.

Now i am better than before.

Thanks

Please use plain text.
New Developer
bold_storm
Posts: 10
Registered: ‎02-22-2009
My Device: Not Specified

Re: How to set Image in Title of The Screen

Hi bikas,

 

Thanks for your solution. It works well with any "title"-field. I even modified it a bit, to have a static "bottom"-field. Besides the black shadow in the title, this also solves my issues with a background that shall be painted behind the whole screen. I could not solve this with setTitle and setStatus.

Please use plain text.