Codenmae之一如何使在图标上面添加一个芽,并将其放置在工具栏中。

问题描述 投票:1回答:2

这是我试过的

notification = Command.create("", materialIcon(FontImage.MATERIAL_NOTIFICATIONS, 3, 0xffffff), evt -> {
       ////....
    });
    mainForm.getToolbar().addCommandToRightBar(notification);

that's what I have managed to do so far

我想实现以下目标

enter image description here

codenameone toolbar
2个回答
2
投票

给一个任意的按钮打上标签是非常容易的。https:/www.codenameone.comblogbadging-arbitrary-components.html

Button chat = new Button("");
FontImage.setMaterialIcon(chat, FontImage.MATERIAL_CHAT, 7);

FloatingActionButton badge = FloatingActionButton.createBadge("33");
hi.add(badge.bindFabToContainer(chat, Component.RIGHT, Component.TOP));

不过工具栏的按钮是封装的,不应该是徽章。

要解决这个问题就不要在标题区添加命令。相反,通过添加您自己的标题标签和一个您喜欢的任何风格的徽章按钮来创建一个完全自定义的标题区域。你可以通过使用 setTitleComponent 而不是 setTitle 和避免 add*Command 方法来实现这些按钮。


0
投票

这就是我如何在工具栏中放置图标的方法。

Button notifiations = new Button("");
    notifiations.setIcon(materialIcon(FontImage.MATERIAL_NOTIFICATIONS, 3, ColorUtil.WHITE));

    FloatingActionButton badge = FloatingActionButton.createBadge("2");
    badge.setUIID("Notification-Badge");
Container notiCnt = BoxLayout.encloseX(badge.bindFabToContainer(notifiations, Component.RIGHT, Component.TOP));

mainForm.getToolbar().add(BorderLayout.EAST, FlowLayout.encloseRightMiddle( notiCnt));
© www.soinside.com 2019 - 2024. All rights reserved.