我们想要这种格式的对话框消息并查看和填充
代号:警报对话框消息-LMLPHP

你能告诉我如何解决它。我的应用程序需要在所有平台(Android、iOS、Windows)上都得到支持,而且我不想为所有平台单独编写 native 代码。

最佳答案

实际上,在 Codename One 中自定义外观更容易,因为所有内容都是用 Java 编写的,您可以从字面上自定义有关任何外观的所有内容。

为了简单起见,我使用了代码而不是更好的样式,您可以在主题设计器中自定义 Dialog UIID 和其他 UIID,以获得更大的灵活性并使其更容易。但是,这需要很多截图和解释,所以我在代码中进行了自定义:

Form f = new Form("Test");
Button b = new Button("Show Dialog");
f.add(b);
b.addActionListener(e -> {
    Dialog dlg = new Dialog("Authentication");
    Style dlgStyle = dlg.getDialogStyle();
    dlgStyle.setBorder(Border.createEmpty());
    dlgStyle.setBgTransparency(255);
    dlgStyle.setBgColor(0xffffff);

    Label title = dlg.getTitleComponent();
    title.setIcon(finalDuke.scaledHeight(title.getPreferredH()));
    title.getUnselectedStyle().setFgColor(0xff);
    title.getUnselectedStyle().setAlignment(Component.LEFT);

    dlg.setLayout(BoxLayout.y());
    Label blueLabel = new Label();
    blueLabel.setShowEvenIfBlank(true);
    blueLabel.getUnselectedStyle().setBgColor(0xff);
    blueLabel.getUnselectedStyle().setPadding(1, 1, 1, 1);
    blueLabel.getUnselectedStyle().setPaddingUnit(Style.UNIT_TYPE_PIXELS);
    dlg.add(blueLabel);
    TextArea ta = new TextArea("This is the text you want to appear in the dialog, this might line break if the text is too long...");
    ta.setEditable(false);
    ta.setUIID("DialogBody");
    ta.getAllStyles().setFgColor(0);
    dlg.add(ta);

    Label grayLabel = new Label();
    grayLabel.setShowEvenIfBlank(true);
    grayLabel.getUnselectedStyle().setBgColor(0xcccccc);
    grayLabel.getUnselectedStyle().setPadding(1, 1, 1, 1);
    grayLabel.getUnselectedStyle().setPaddingUnit(Style.UNIT_TYPE_PIXELS);
    dlg.add(grayLabel);

    Button ok = new Button(new Command("OK"));
    ok.getAllStyles().setBorder(Border.createEmpty());
    ok.getAllStyles().setFgColor(0);
    dlg.add(ok);
    dlg.showDialog();
});
f.show();

代号:警报对话框消息-LMLPHP

我建议在主题设计器中进行对话框自定义并使用更好看的 9 件式图像边框。

关于代号:警报对话框消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38802224/

10-12 03:51
查看更多