Dialog类中没有标题,我建议使用PopupScreen扩展:
alt text http://img187.imageshack.us/img187/6245/9000.jpg
class GlobalDialog extends PopupScreen implements FieldChangeListener {
ButtonField mOKButton = new ButtonField("OK", ButtonField.CONSUME_CLICK
| FIELD_HCENTER);
public GlobalDialog(String title, String text) {
super(new VerticalFieldManager());
add(new LabelField(title));
add(new SeparatorField(SeparatorField.LINE_HORIZONTAL));
add(new LabelField(text, DrawStyle.HCENTER));
mOKButton.setChangeListener(this);
add(mOKButton);
}
public void fieldChanged(Field field, int context) {
if (mOKButton == field)
close();
}
}
使用示例:
class Scr extends MainScreen {
public Scr() {
synchronized (UiApplication.getEventLock()) {
UiEngine ui = Ui.getUiEngine();
String title = "Dialog Title";
String text = "Lorem ipsum dolor sit amet, consectetur "
+ "adipiscing elit. Donec venenatis "
+ "condimentum urna, non accumsan magna "
+ "ultrices ut. Morbi fringilla ";
GlobalDialog screen = new GlobalDialog(title, text);
ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
}
}
}
根据费尔南多评论更新