We cabn make a titlebar rather than using a default one. please copy the code and you can use and customize further
TitleBarText.java
import onepoint.blackberry.gfk.utility.all.FontDetails;
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.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
public class TitleBarText extends Field implements DrawStyle
{
private int fieldWidth;
private int fieldHeight;
private int fontColour;
private int backgroundColor;
private int BACKGROUND_COLOR = 0x00000000;
private String label;
public TitleBarText(int height,int BACKGROUND_COLOR_,String text,int fontsize)
{
super(Field.NON_FOCUSABLE);
fieldHeight =height;
fieldWidth = Display.getWidth();
//background color is black
backgroundColor = BACKGROUND_COLOR_;
label=text;
this.setFont(...);//set you font here for this field
}
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);
graphics.setColor(Color.WHITE);
graphics.drawText(label, 10, (h-getFont().getHeight())/2);
}
}
TitleBarText.java
import onepoint.blackberry.gfk.utility.all.FontDetails;
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.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
public class TitleBarText extends Field implements DrawStyle
{
private int fieldWidth;
private int fieldHeight;
private int fontColour;
private int backgroundColor;
private int BACKGROUND_COLOR = 0x00000000;
private String label;
public TitleBarText(int height,int BACKGROUND_COLOR_,String text,int fontsize)
{
super(Field.NON_FOCUSABLE);
fieldHeight =height;
fieldWidth = Display.getWidth();
//background color is black
backgroundColor = BACKGROUND_COLOR_;
label=text;
this.setFont(...);//set you font here for this field
}
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);
graphics.setColor(Color.WHITE);
graphics.drawText(label, 10, (h-getFont().getHeight())/2);
}
}
No comments:
Post a Comment