如何为Dialog设置背景图片?

发布于 2024-12-18 17:26:57 字数 246 浏览 3 评论 0原文

我正在尝试这样做:

public class DialogMenuHawaii extends Dialog {

    Style s = UiFactory.getBaseStyle();
    s.setBgTransparency(0);
    s.setBgImage( <my image >);
    this.setUnselectedStyle(s);
}

但它不起作用。

I am trying to do this:

public class DialogMenuHawaii extends Dialog {

    Style s = UiFactory.getBaseStyle();
    s.setBgTransparency(0);
    s.setBgImage( <my image >);
    this.setUnselectedStyle(s);
}

but it doesn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

羁绊已千年 2024-12-25 17:26:57

首先,我建议您使用主题。我们不断地更改小的实现细节,例如,像您所做的那样的自定义将无法在 LWUIT 1.4 和 1.5 之间移植。没有任何理由不为这样的事情使用主题。

如果您对将视图逻辑手动编码到应用程序中的痛苦感兴趣,您可以使用多种方法(例如 getDialogComponent())从中获取样式并对其进行操作。对话框是一个复杂的野兽,因为它实际上是一种远离边缘的形式。

First, I suggest you use a theme. We constantly change small implementation details e.g. customizations like the one you are doing will not be portable between LWUIT 1.4 and 1.5. There is no reason whatsoever not to use a theme for something like this.

If you are interested in the pain and suffering of manually coding view logic into your application you can use several methods such as getDialogComponent() to get the style from them and manipulate that. Dialog is a complex beast due to the fact that its really a form padded away from the edges.

终难愈 2024-12-25 17:26:57

在资源编辑器中打开“.res”文件并选择您喜欢的主题,

  1. 在“未选择”选项卡下打开 DialogContentPane 样式,如果您没有创建它,请查看此答案的末尾如何做到这一点?,并将背景图像设置为您需要显示为对话框 bg 的图像,
  2. 在“未选择”选项卡下打开 DialogBody 样式,如果您没有创建它,请查看本回答结束上如何做?,并将背景透明度设置为“0”,并确保背景图像类型为NONE

注意:上面的代码将反映应用程序中的所有对话框。如果您想要一个带有背景图像的特定对话框,则可以从这些默认样式中派生新样式,然后按照上述步骤将其应用到您的 DialogMenuHawaii 或任何运行时对话框

操作方法:我建议您阅读 Shai 的博客文章 LWUIT 资源编辑器教程第 1 部分 到第 10 部分。为了更好地了解资源编辑器的特性和功能。

:

: :

PS: 通过编程方式,我无法使用 TextArea 来实现它,这是默认对话框的情况。如果将对话框主体组件替换为 Label 如果工作正常,则代码示例如下。我还没有深入研究为什么会这样?也许我会在空闲时间做。因此,我提出了一个可行的替代解决方案,上面使用资源编辑器编写脚本,下面使用代码编写

class MyDialog extends Dialog {

    public void show() {
        Container octnPane = this.getDialogComponent();
        octnPane.getUnselectedStyle().setBgTransparency(0, false);

        Container ctnPane = (Container)((BorderLayout)octnPane.getLayout()).getCenter();
        ctnPane.getUnselectedStyle().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED, false);
        ctnPane.getUnselectedStyle().setBgImage(myImage, false);

        Label t = new Label("Dialog");
        t.setUIID("DialogBody");
        t.getUnselectedStyle().setBgTransparency(0, false);
        ctnPane.addComponent(t);

        super.show();
    }
}

Open your '.res' file in resource Editor and select your preferred theme,

  1. Under 'Unselected' tab open the DialogContentPane style, if you don't have one create it look at the end of this answer on HOW TO DO IT?, and set the background image to the image you need to show as Dialog bg
  2. Under 'Unselected' tab open the DialogBody style, if you don't have one create it look at the end of this answer on HOW TO DO IT?, and set the background transparency as '0' and also make sure the background image type is NONE

NOTE: The above code will reflect for all the Dialogs in your application. If you want a particular dialog with background image than derive new styles from these default styles, and follow the above steps to apply it to your DialogMenuHawaii or any runtime Dialogs.

HOW TO: I would recommend you to go through the Shai's blog posts LWUIT Resource Editor Tutorial Part 1 till part 10. To better understand the Resouce Editor its features and capabilities.

:

:

:

PS: Programmatic-ally i haven't been able to achieve it using TextArea which is the case for default Dialog's. If you replace the dialog body component with Label if works fine, the code sample is given below. I haven't delved much into why is it so ? maybe will do it in my free time. Hence i have proposed a working alternative solution which is scripted above using Resource Editor and below using the code

class MyDialog extends Dialog {

    public void show() {
        Container octnPane = this.getDialogComponent();
        octnPane.getUnselectedStyle().setBgTransparency(0, false);

        Container ctnPane = (Container)((BorderLayout)octnPane.getLayout()).getCenter();
        ctnPane.getUnselectedStyle().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED, false);
        ctnPane.getUnselectedStyle().setBgImage(myImage, false);

        Label t = new Label("Dialog");
        t.setUIID("DialogBody");
        t.getUnselectedStyle().setBgTransparency(0, false);
        ctnPane.addComponent(t);

        super.show();
    }
}
掀纱窥君容 2024-12-25 17:26:57

这是对话框背景。

Dialog dialog = new Dialog();
dialog.getDialogStyle().setBgImage(Image.createImage("/image/image.png"));

如果你想设置带有图像的对话框的透明度。

dialog.getStyle().setBgImage(Image.createImage("/image/image.png");

This is for Dialog background.

Dialog dialog = new Dialog();
dialog.getDialogStyle().setBgImage(Image.createImage("/image/image.png"));

If you want to set transparency of Dialog with image.

dialog.getStyle().setBgImage(Image.createImage("/image/image.png");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文