徽章TitleArea命令

时间:2018-12-28 15:26:02

标签: codenameone

我有一个表格,其中的命令添加到了标题区域的右侧。我想在命令图标上加上动态值。

Thats the icon i will like to badge

我已经查看了Command的文档,似乎没有徽章的方法

1 个答案:

答案 0 :(得分:1)

您需要先将命令转换为组件:

Command cmd = tb.addMaterialCommandToRightSide(...);
Button btn = tb.findCommandComponent(cmd);
Container cnt = btn.getParent();
btn.remove();
FloatingActionButton fab = FloatingActionButton.createBadge("" + number);
cnt.add(badge.bindFabToContainer(btn, Component.RIGHT, Component.TOP));

请注意,此操作只能使用一次,因此,如果要更新编号,则需要在此处保存一些组件并删除/替换它们。