【问题标题】:Codename One - customize Dialog style not working代号一 - 自定义对话框样式不起作用
【发布时间】:2019-12-27 14:45:25
【问题描述】:

我想要一个自定义的Dialog 样式,具有另一种背景颜色和圆角边框,因为它看起来比默认的灰色矩形更好。

通过设置DialogContentpane 的样式,这部分是可能的。问题是,底层对话框样式仍然存在,其中显示了内容窗格。而且似乎Dialog UDID本身无法更改,“Dialog”样式也无法在设计器中被覆盖,也无法被代码覆盖。

    Form hi = new Form();
    hi.getUnselectedStyle().setBgColor(0xffffff);
    Button but = new Button("open dialog");
    but.addActionListener(e -> {
        Dialog d = new Dialog(BoxLayout.y());

        d.setUIID("Container"); // this line has no effect, the outside dialog component is still visible

        Style s = d.getContentPane().getUnselectedStyle();
        s.setBorder(RoundRectBorder.create());
        s.setBgColor(0x00ff00);
        s.setBgTransparency(255);
        s.setMargin(5, 5, 5, 5); // adding some margin between contentpane and Dailog container, to be more obvious
        d.setDisposeWhenPointerOutOfBounds(true);

        // title
        Label title = new Label();
        title.setText("Confirmation");
        d.add(title);

        // body field with spanlabel info text
        SpanLabel bodyLabel = new SpanLabel("Body Text");
        d.add(bodyLabel);

        // delete button
        Button okButton = new Button("Ok");
        okButton.addActionListener(e2 -> {
            d.dispose();
        });

        // exit button
        Button exitButton = new Button("Cancel");
        exitButton.addActionListener(e3 -> {
            d.dispose();
        });
        d.add(GridLayout.encloseIn(2, okButton, exitButton));

        d.show();
    });

    hi.add(but);
    hi.show();

在上图中,最外面的深灰色是对话框外的着色区域。绿色是带有预期圆形边框的内容窗格。中间的浅灰色来自我想去掉的Dialog风格。

这个可以吗?

【问题讨论】:

    标签: dialog styles codenameone


    【解决方案1】:

    简答:setDialogUIID("Container");

    但是,通过代码自定义对话框有点问题,我强烈建议通过设计器/css 对它们进行样式设置,因为我们只是没有为手动样式设计它们,因此您依赖可能会破坏的内部实现细节。

    当您在Dialog 上调用getContentPane() 时,您正在为Dialog 的内容窗格设置样式。不是Dialog 本身,所以对话框样式仍然具有非透明背景。您可以使用getDialogStyle() 来设置Dialog 本身的样式。我不确定它的效果如何。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-23
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多