Thick border for rounded button in blackberry

2019-06-12 11:12发布

问题:

I am getting this... I want the below image I am newbee in Blackberry.

I want to give thick border to the rounded button field in my application.

Below is my code.

I have created a CustomBasicEditField class.

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

If I make drawRoundRect(0,0,fieldWidth, fieldHeight, 0, 0), then it prints a square with thick border.

But I don't want a square. When I keep the above code, it does create a rounded edit box but a thin border.

Thanks in advance.

回答1:

Try this code:

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

I got like this:



回答2:

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


回答3:

Try this, it work fine.

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