我在我的黑莓程序中使用了 BasicEditField,BasicEditField 不显示任何边框。所以我想自定义 BasicEditField 以显示边框。请提供一些代码片段。
问问题
11456 次
2 回答
19
如果是 4.6 RIM OS,为什么不使用Border:
BasicEditField roundedBorderEdit = new BasicEditField();
XYEdges padding = new XYEdges(15, 15, 15, 15);
int color = Color.CRIMSON;
int lineStyle = Border.STYLE_DOTTED;
Border roundedBorder = BorderFactory.createRoundedBorder(padding,
color, lineStyle);
roundedBorderEdit.setBorder(roundedBorder);
BasicEditField bevelBorderEdit = new BasicEditField();
XYEdges edges = new XYEdges(10, 10, 10, 10);
XYEdges outerColors = new XYEdges(Color.BLACK, Color.WHITE,
Color.BLACK, Color.WHITE);
XYEdges innerColors = new XYEdges(Color.WHITE, Color.BLACK,
Color.WHITE, Color.BLACK);
Border bevelBorder = BorderFactory.createBevelBorder(edges,
outerColors, innerColors);
bevelBorderEdit.setBorder(bevelBorder);
如果您的 BlackBerry OS 版本为 4.5 及更早版本,您可以尝试在绘制事件时绘制带边框的位图:
class BorderedEdit extends BasicEditField
{
Bitmap mBorder = null;
public BorderedEdit(Bitmap borderBitmap) {
mBorder = borderBitmap;
}
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, mBorder.getWidth(),
mBorder.getHeight(), mBorder, 0, 0);
super.paint(graphics);
}
}
于 2009-07-16T06:07:49.640 回答
6
重写paint方法如下:
editField= new BasicEditField(..parameters here..) {
public void paint(Graphics g) {
super.paint(g);
g.drawRect(0, 0, getWidth(), getHeight());
}
};
于 2009-07-16T05:58:26.710 回答