我在Blackberry程序中使用了BasicEditField,Basic Edit Field不显示任何边框。因此,我想自定义BasicEditField以显示border。请提供一些代码段。

最佳答案

如果是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);
    }
}

关于user-interface - 黑莓-如何为BasicEditField添加边框?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1135349/

10-12 03:13