Thick border for rounded button in blackberry

ぃ、小莉子 提交于 2019-12-08 12:18:49

问题


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


来源:https://stackoverflow.com/questions/8927472/thick-border-for-rounded-button-in-blackberry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!