我正在尝试为黑莓创建自定义对话框...
public class cusDialog extends Screen implements FieldChangeListener {
private cusButtField okButton;
protected void paintBackground(Graphics graphics) { /// this doesn't seem to work.
graphics.setColor(0x999966); /// should I somehow call it?
graphics.fillRoundRect(0, 0, getWidth(), getHeight(), 12, 12);
graphics.setColor(Color.BLACK);
graphics.drawRoundRect(0, 0, getWidth(), getHeight(), 12, 12);
}
public cusDialog(String message) {
super(new VerticalFieldManager(), Screen.DEFAULT_CLOSE);
try {
FontFamily alphaSansFamily = FontFamily.forName("BBAlpha Serif");
Font appFont = alphaSansFamily.getFont(Font.PLAIN, 9, Ui.UNITS_pt);
setFont(appFont);
} catch (ClassNotFoundException e) {
}
add(new LabelField(message));
add(new SeparatorField());
okButton = new cusButtField("OK", Color.WHITE, Color.LIGHTGREY, Color.YELLOW, Color.GREEN,Field.FIELD_HCENTER);
okButton.setChangeListener(this);
add(okButton);
}
protected void sublayout(int width, int height) {
layoutDelegate(width - 80, height - 80);
setPositionDelegate(10, 10);
setExtent(width - 60, Math.min(height - 60, getDelegate().getHeight() + 20));
setPosition(30, (height - getHeight())/2);
}
public void fieldChanged(Field field, int context) {
if (field == okButton) {
close();
}
}
}
但上面的“paintBackground”部分不起作用,即对话框出现在白色背景上。如果我以某种方式调用此方法,您认为可能是错的?我应该放在其他地方吗?
谢谢!
答案 0 :(得分:2)
我刚才在JDE 4.5上遇到过同样的问题。正如here (Blackberry-KB)所述,下面的代码对我有用。
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(Color.DARKRED);
graphics.clear();
super.paint(graphics);
}
另外,您可能需要查看this问题。