简体   繁体   English

LWUIT资源编辑器:创建按钮

[英]LWUIT Resource Editor: Creating a Button

I think I need to create a button style in the LWUIT Resource Editor since I'm not able to change the background color and other properties of buttons in my J2ME app. 我认为我需要在LWUIT资源编辑器中创建按钮样式,因为我无法更改J2ME应用程序中按钮的背景颜色和其他属性。 I have no idea how to accomplish this, and all the tutorials and examples are very confusing and unhelpful. 我不知道如何完成此操作,所有教程和示例都非常混乱且无济于事。

So if I want to have a button with a custom style, how do I go about creating this in the resource editor, and then how do I access this in my app? 因此,如果我想使用自定义样式的按钮,该如何在资源编辑器中创建它,然后如何在我的应用程序中访问它?

Thanks! 谢谢!

Suggested readings: Using Styles, Themes, and Painters with LWUIT and LWUIT Tutorial - Styles and Themes to understand the style concept. 建议的阅读材料: 在LWUITLWUIT教程-样式和主题中 使用样式,主题和画家以了解样式概念。

First step you need to create a new theme. 第一步,您需要创建一个新主题。 Open LWUIT resource editor and then create a new theme: 打开LWUIT资源编辑器,然后创建一个新主题:

在此处输入图片说明

Then you have to add a button style for Unselected , Selected , Pressed and Disabled styles as you wish (no need to do it for all of these just which ones needed, most commonly Unselected and Pressed ): 然后,您需要根据需要为UnselectedSelectedPressedDisabled样式添加按钮样式(无需对所有这些样式都需要这样做,最常见的是UnselectedPressed ):

在此处输入图片说明

在此处输入图片说明

Save your theme in a .res file (let say MyTheme.res ) clicking in Save option (please note a single .res file may contain several themes). 单击“ Save选项,将您的主题保存为.res文件(假设为MyTheme.res )(请注意,单个.res文件可能包含多个主题)。 Copy MyTheme.res file into your project, let say in res folder and please don't forget to add this folder in project properties so when you generate your jar file it will be included. MyTheme.res文件复制到您的项目中,在res文件夹中说,请不要忘记在项目属性中添加此文件夹,以便在生成jar文件时将其包括在内。 Finally load your theme like this: 最后像这样加载您的主题:

Resources r = Resources.open("/res/MyTheme.res");
UIManager.getInstance().setThemeProps(r.getTheme("MyTheme"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM