2

我想为黑莓上的弹出屏幕添加一个白色边框。我使用此代码添加边框

Popup x = new Popup();
Border borderFocus = BorderFactory.createRoundedBorder(new XYEdges(10, 10, 10, 10), 0xffffff, Border.STYLE_SOLID);
x.getDelegate().setBorder(borderFocus);

/////////////////弹出类//////////////////

public class Popup extends PopupScreen {

    public Popup() {
        super(new VerticalFieldManager(), Field.FOCUSABLE);

        HorizontalFieldManager hfm = new HorizontalFieldManager(
                Field.USE_ALL_WIDTH | FIELD_VCENTER);
        HorizontalFieldManager hfmBtn = new HorizontalFieldManager(
                Field.USE_ALL_WIDTH | FIELD_VCENTER | FIELD_HCENTER);


        LabelField title_screen = new LabelField("ddd");
        title_screen.setPadding(11, 5, 0, 0);
        hfm.add(title_screen);


        add(hfm);
        add(new SeparatorField());

        add(new LabelField(""));
        final LabelField labelVersion = new LabelField("ffffffffffffff");

        ButtonField btn_cancel = new ButtonField(
                "cancel");


        ButtonField btn_ok = new ButtonField("Yes");

        btn_ok.setPadding(0, 0, 0, 60);
        add(labelVersion);

        hfmBtn.add(btn_cancel);
        hfmBtn.add(btn_ok);
        add(new LabelField(""));
        add(hfmBtn);

    }

    public void sublayout(int width, int height){

        super.sublayout(width,height);

        setPosition(35,65);

    }
    public boolean onClose() {
        UiApplication.getUiApplication().popScreen();

        return true;

    }

但是我将边框放入弹出窗口,并且弹出窗口没有白色边框。

在此处输入图像描述

4

2 回答 2

2

我不确定这是否是解决问题的最简单方法,但它对我有用。

基本上,默认边框PopupScreen会导致问题。即使您将代码更改为:

x.getDelegate().setBorder(borderFocus);

x.setBorder(borderFocus);

它看起来不正确(圆形边框外有一个矩形框)。

所以,我基本上做的是这样的:

  1. 使默认PopupScreen边框和背景完全清晰/透明。
  2. 重写类paintBackground(Graphics)中的方法Popup,手动绘制纯色背景,再绘制圆角白色边框。

因此,将其添加到您的Popup课程中:

   public class Popup extends PopupScreen {

      protected void paintBackground(Graphics g) {
         int oldColor = g.getColor();
         
         // we'll have to draw in the background, since we blanked it in
         //  the constructor
         g.setColor(Color.BLACK);
         int arcWidth = 20;
         g.fillRoundRect(0, 0, getWidth(), getHeight(), arcWidth , arcWidth);
         // and now, draw in the border manually
         g.setColor(Color.WHITE);
         g.drawRoundRect(0, 0, getWidth(), getHeight(), arcWidth , arcWidth);
         
         g.setColor(oldColor);
      }

      public Popup() {
         super(new VerticalFieldManager(), Field.FOCUSABLE);

         // make the screen's default border/background completely transparent
         setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 0));
         setBorder(BorderFactory.createRoundedBorder(new XYEdges(), Border.STYLE_TRANSPARENT));
         // use some padding to compensate for getting rid of the screen's default border
         int pad = 10
         setPadding(pad, pad, pad, pad);

         /** The rest of the constructor is as you originally had it */

然后你可以删除这些行:

Border borderFocus = BorderFactory.createRoundedBorder(new XYEdges(10, 10, 10, 10), 0xffffff, Border.STYLE_SOLID);
x.getDelegate().setBorder(borderFocus);

因为现在是在paintBackground()方法中手动完成的。

结果

在此处输入图像描述

于 2013-04-30T09:54:34.120 回答
0

我记得,您需要在 PopupScreen 上覆盖一个未记录的方法,以消除弹出屏幕上的黑色边框。那就是applyTheme- 只需用一个空的主体来实现它以避免黑色边框,然后您自己的设置应该按照您期望的方式工作。

protected void applyTheme() {

}
于 2013-05-02T02:12:21.970 回答