Blackberry - 如何为BasicEditField添加边框?

时间:2009-07-16 04:12:11

标签: user-interface blackberry border

我在Blackberry程序中使用BasicEditField,BasicEditField不显示任何边框。所以我想自定义BasicEditField以显示border.please给出一些代码片段。

2 个答案:

答案 0 :(得分: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);
    }
}

答案 1 :(得分:6)

覆盖paint方法如下:

editField= new BasicEditField(..parameters here..) {
            public void paint(Graphics g) {
                super.paint(g);
                g.drawRect(0, 0, getWidth(), getHeight());
            }
        };