我在应用程序中添加SideMenu时遇到问题

时间:2019-10-27 12:03:58

标签: java codenameone

当我使用代码添加SideMenu时,我无法通过java给我您有问题,但无法解决该问题 enter image description here

可以帮助我修复代码或给我另一个代码。

Form hi = new Form("Hi World");
Toolbar tb = hi.getToolbar();
Image icon = theme.getImage("mu.png");
Container topBar = BorderLayout.east(new Label());
topBar.add(BorderLayout.SOUTH, new Label("Cool App
 Tagline...", "SidemenuTagline","));
topBar.setUIID("SideCommand");
tb.addComponentToSideMenu(topBar);
tb.addMaterialCommandToSideMenu("Home", FontImage.MATERIAL_HOME, e ->
 {});
tb.addMaterialCommandToSideMenu("Website", FontImage.MATERIAL_WEB, e ->
 {});
tb.addMaterialCommandToSideMenu("Settings", FontImage.MATERIAL_SETTINGS, e
 -> {});
tb.addMaterialCommandToSideMenu("About", FontImage.MATERIAL_INFO, e ->
 {});
hi.addComponent(new Label("Hi World"));
hi.show();

1 个答案:

答案 0 :(得分:0)

theme是应该已经创建的资源文件。如果您在主类中,那么由于创建主类,theme变量应该已经存在。如果没有,您可以在代码的主体中通过在代码之前添加以下行来创建它:

Resources theme = getGlobalResources();

请注意,您需要使用设计器工具或CSS将图像mu显式添加到res文件中。

我还注意到您对此代码有后续问题:

topBar.add(BorderLayout.SOUTH, new Label("Cool App
 Tagline...", "SidemenuTagline","));

在Java中,您不能在中间中断字符串,如果要添加换行符,则需要这样使用\n

topBar.add(BorderLayout.SOUTH, new Label("Cool App\nTagline...", "SidemenuTagline","));
相关问题