我得到这个...我想要下面的图像 我是Blackberry中的新手。
我想为应用程序中的圆角按钮字段添加粗边框。
以下是我的代码。
我创建了一个CustomBasicEditField类。
protected void paint(Graphics graphics)
{
int x = (this.getWidth() - getFont().getAdvance(text)) >> 1;
int y = (this.getHeight() - getFont().getHeight()) >> 1;
graphics.setColor(backgroundColour);
graphics.fillRoundRect(0, 0, fieldWidth, fieldHeight, 40, 40);
graphics.setColor(border_color);
graphics.setStrokeWidth(5);
graphics.drawRoundRect(0, 0, fieldWidth, fieldHeight, 40, 40);
graphics.setColor(0x2bb1ff);
graphics.setFont(myFont);
graphics.drawText(text, x, y);
super.paint(graphics);
}
如果我制作drawRoundRect(0,0,fieldWidth,fieldHeight,0,0),那么它会打印一个边框较粗的正方形。
但我不想要一个正方形。当我保留上面的代码时,它确实创建了一个圆形编辑框,但是边框很薄。
提前致谢。
答案 0 :(得分:2)
试试这段代码:
public class LoadingScreen extends MainScreen
{
ButtonField save;
public LoadingScreen()
{
setTitle("Loading Screen");
createGUI();
}
private void createGUI()
{
VerticalFieldManager vr=new VerticalFieldManager();
Border border=BorderFactory.createRoundedBorder(new XYEdges(5,5,5,5),Color.RED,Border.STYLE_FILLED);
// give XYEdges(10,10,10,10) and see the difference;
save=new ButtonField("Save");
save.setBorder(border);
vr.add(save);
vr.setPadding(5, 5, 5, 5);
add(vr);
}
public boolean onMenu(int instance)
{
return true;
}
}
我是这样的:
答案 1 :(得分:1)
Bitmap borderBitmap = //a ![your image]
VerticalFieldManager vfm_email = new VerticalFieldManager();
vfm_email.setBorder(BorderFactory.createBitmapBorder(new XYEdges(5, 5,
5, 5), borderBitmap));
vfm_email.setMargin(m, 30, 0, 30);
email = new EmailAddressEditField(" ", "", 50, Field.FOCUSABLE);
vfm_email.add(email);
vfm_.add(vfm_email);
答案 2 :(得分:0)
试试这个,它运作正常。
Border myBorder = BorderFactory.createBitmapBorder(new XYEdges(10, 10, 10, 10),
Bitmap.getBitmapResource("border.png"));
BasicEditField edt_searchText = new BasicEditField(TextField.NO_NEWLINE)
{
protected void paint(Graphics g)
{
if (getTextLength() == 0)
{
g.setColor(Color.LIGHTGRAY);
g.drawText("Search weeds", 0, 0);
}
g.setColor(Color.BLACK);
super.paint(g);
}
};
edt_searchText.setBorder(myBorder);