codename one 使用 gui builder 和 css。

codename one using gui builder and css.

我正在构建一个 cn1 应用程序,目前使用 GUI Builder 中的 "Theme" 来更改容器和按钮的外观。我现在想向容器添加特定边框,我发现通过 css 更容易完成边框,我在此处找到了有关如何操作的说明和代码:https://www.codenameone.com/blog/rounded-corners-shadows-and-gradients-with-css.html。我添加了 .jar,创建了一个 css 文件夹并添加了我的 theme.css 文件和代码。在我的表单的 beforeshow 方法中,我将容器的 uiid 更改为我的 theme.css 中定义的 uiid。但是,当我 运行 应用程序时,容器采用默认的 Container uiid,而不是我的 .css 中定义的那个。我觉得这是因为我已经在我的 gui 构建器中用我的 uiid 定义了一个主题,现在我正在尝试将容器的 uiid 更改为另一个主题中定义的 uiid。我这里有什么地方做错了吗?

如果我的理解正确的话,您有两个主题,并且您想在应用中使用这两个主题中的元素。有两种有效的场景,一种是两个主题都在同一个 res 文件中,另一种是两个主题都在一个单独的文件中。

如果它们在同一个 res 文件中,请执行此操作:

theme = UIManager.initNamedTheme("/theme", "firstTheme");
UIManager.getInstance().addThemeProps(theme.getTheme("secondTheme"));

如果它们在单独的文件中,请执行以下操作:

theme = UIManager.initNamedTheme("/theme", "firstTheme");
Resources otherTheme = Resources.openLayered(("/otherTheme");
UIManager.getInstance().addThemeProps(otherTheme.getTheme("secondTheme"));

这在 Codename One Developer Guide 主题分层下进行了讨论。