如何为Dialog设置背景图片?
我正在尝试这样做:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,我建议您使用主题。我们不断地更改小的实现细节,例如,像您所做的那样的自定义将无法在 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.在资源编辑器中打开“.res”文件并选择您喜欢的主题,
注意:上面的代码将反映应用程序中的所有对话框。如果您想要一个带有背景图像的特定对话框,则可以从这些默认样式中派生新样式,然后按照上述步骤将其应用到您的 DialogMenuHawaii 或任何运行时对话框。
操作方法:我建议您阅读 Shai 的博客文章 LWUIT 资源编辑器教程第 1 部分 到第 10 部分。为了更好地了解资源编辑器的特性和功能。
:
: :
PS: 通过编程方式,我无法使用 TextArea 来实现它,这是默认对话框的情况。如果将对话框主体组件替换为 Label 如果工作正常,则代码示例如下。我还没有深入研究为什么会这样?也许我会在空闲时间做。因此,我提出了一个可行的替代解决方案,上面使用资源编辑器编写脚本,下面使用代码编写
Open your '.res' file in resource Editor and select your preferred theme,
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
这是对话框背景。
如果你想设置带有图像的对话框的透明度。
This is for Dialog background.
If you want to set transparency of Dialog with image.