我想在黑莓手机上为弹出屏幕添加白色边框。 我使用此代码添加边框
Popup x = new Popup();
Border borderFocus = BorderFactory.createRoundedBorder(new XYEdges(10, 10, 10, 10), 0xffffff, Border.STYLE_SOLID);
x.getDelegate().setBorder(borderFocus);
/////////////////// class Popup /////////////////////
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;
}
但是我将边框插入弹出窗口,弹出窗口没有白色边框。
答案 0 :(得分:2)
我不确定这是解决问题的最简单方式,但它对我有用。
基本上,PopupScreen
的默认边框会导致问题。即使您更改了代码:
x.getDelegate().setBorder(borderFocus);
到
x.setBorder(borderFocus);
它看起来不正确(圆形边框外面有一个矩形框)。
所以,我基本上做的是:
PopupScreen
边框和背景完全清晰/透明。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()
方法中手动完成了这项工作。
答案 1 :(得分:0)
我记得,在PopupScreen上需要覆盖一个未记录的方法,以消除弹出屏幕上的黑色边框。那是applyTheme
- 只需用空体来实现它以避免黑色边框,那么你自己的设置应该按照你期望的方式工作。
protected void applyTheme() {
}