0

我得到了这个......我想要下面的图像 在此处输入图像描述我是黑莓的新手。

我想在我的应用程序中为圆形按钮字段提供粗边框。

下面是我的代码。

我创建了一个 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),那么它会打印一个带有粗边框的正方形。

但我不想要一个正方形。当我保留上面的代码时,它确实创建了一个圆形的编辑框,但边框很细。

提前致谢。

4

3 回答 3

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;
}
}

我得到了这样的:

圆形边框按钮

于 2012-01-19T14:46:54.803 回答
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);
于 2012-02-02T12:07:42.503 回答
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);     
于 2012-03-07T10:05:50.500 回答