首页 > 解决方案 > Codenmae 一个如何在图标顶部添加预算并将它们放在工具栏中

问题描述

这是我试过的

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

这就是我到目前为止所做的

我想在下面实现这一点

在此处输入图像描述

标签: codenameonetoolbar

解决方案


标记任意按钮非常简单:https ://www.codenameone.com/blog/badging-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这些按钮的方法来做到这一点。


推荐阅读