12-22-2011 06:42 AM
i have a screen on which i apply label field . in that label field i put string from resource.how to format that string.
Solved! Go to Solution.
12-22-2011 07:17 AM
Format means,
What you want excatly?
12-22-2011 09:52 AM
I want to show resource String in to Screen .
format means :
change some text size and font and color of resource string.
12-22-2011 10:01 AM
Then create a LabelField which contains that string as label.
set font size and color to that label field.
now add that labelfield to screen.
This is the code snippet.
LabelField label = new LabelField(resourcstring)
{
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLUE);//set your color here
super.paint(graphics);
}
};
//set your font like this
label.setFont(Font.getDefault().derive(Font.BOLD,1 2));//set your own font
//now add this field to screen
Thanks.
12-22-2011 10:46 AM
12-22-2011 10:53 AM
Then try like this
1. String data = "Hello World!";
2. int offsets[] ={0,5,data.length()};
3. Font[] fonts = new Font[] { Font.getDefault(), Font.getDefault()};
4. int bg[] = new int[] { Color.WHITE, Color.WHITE};
5. int fg[] = new int[] { Color.BLACK, Color.RED};
6. byte attributes[] = {0,1};
7. add(new ActiveRichTextField(data, offsets, attributes, fonts, fg, bg, 0));
Thanks.
12-23-2011 02:12 AM
Thanks alot sir code work fine show hello word text but font size color is not change because ActiveRichTextField has only one parameter.
public ActiveRichTextField(String text)
Creates a new ActiveRichTextField instance from provided string after scanning for active "links".
Parameters: text - String to scan and display. one more question how to add web link into screen with this text.
12-23-2011 02:35 AM
You need to change the font size
see this,
String data = "Hello World!";
int offsets[] ={0,5,data.length()};
Font[] fonts = new Font[] { Font.getDefault().derive(Font.BOLD,20), Font.getDefault().derive(Font.BOLD,15)};
int bg[] = new int[] { Color.WHITE, Color.WHITE};
int fg[] = new int[] { Color.BLACK, Color.RED};
byte attributes[] = {0,1};
add(new ActiveRichTextField(data, offsets, attributes, fonts, fg, bg, 0));
And also you need to change foreground and background colors,
For hyperlink you have to write your own field,
This is the sample.
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.system.Characters;
public class HrefField extends Field
{
private String content;
private Font fieldFont;
private int fieldWidth;
private int fieldHeight;
private boolean active = false;
private int backgroundColour = 0xffffff;
//private int textColour = 0x333333;
private int textColour = Color.DARKBLUE;
private int maskColour = 0xffffff;
private int buttonId;
private String buttonName;
public HrefField(String content)
{
super(Field.FOCUSABLE);
this.content = content;
fieldFont = Font.getDefault().derive(Font.UNDERLINED);
fieldWidth = fieldFont.getAdvance(content)+2;
fieldHeight = fieldFont.getHeight();
}
public void setColours(int backgroundColour, int textColour, int maskColour)
{
this.backgroundColour = backgroundColour;
this.textColour = textColour;
this.maskColour = maskColour;
invalidate();
}
public void setBackgroundColour(int backgroundColour)
{
this.backgroundColour = backgroundColour;
invalidate();
}
public void setTextColour(int textColour)
{
this.textColour = textColour;
invalidate();
}
public void setMaskColour(int maskColour)
{
this.maskColour = maskColour;
invalidate();
}
public void setFont(Font fieldFont)
{
this.fieldFont = fieldFont;
}
public int getPreferredWidth()
{
return fieldWidth;
}
public int getPreferredHeight()
{
return fieldHeight;
}
protected void layout(int arg0, int arg1)
{
setExtent(getPreferredWidth(), getPreferredHeight());
}
protected void paint(Graphics graphics)
{
if (active)
{
graphics.setColor(maskColour);
graphics.fillRect(0, 0, fieldWidth, fieldHeight);
}
else
{
graphics.setColor(backgroundColour);
graphics.fillRect(0, 0, fieldWidth, fieldHeight);
}
graphics.setColor(textColour);
graphics.setFont(fieldFont);
graphics.drawText(content, 1, 1);
// graphics.drawLine(1, fieldHeight-2, fieldWidth-2, fieldHeight-2);
}
public void setButtonId(int buttonId)
{
this.buttonId = buttonId;
}
public void setButtonName(String buttonName)
{
this.buttonName = buttonName;
}
public int getButtonId()
{
return buttonId;
}
public String getButtonName()
{
return buttonName;
}
public String getLabel()
{
return buttonName;
}
public boolean keyChar(char key, int status, int time)
{
if (key == Characters.ENTER)
{
fieldChangeNotify(0);
return true;
}
return false;
}
protected void onFocus(int direction)
{
active = true;
invalidate();
}
protected void onUnfocus()
{
active = false;
invalidate();
}
public static Font defaultFont()
{
return Font.getDefault();
}
}
And in this field navigation click connect browser by getting this field's link.
12-23-2011 02:53 AM
12-23-2011 02:59 AM