工具栏组件代号one

Toolbar components codenameone

组件检查器的工具栏中有3个组件(上图)但是如果我想获取menuButton,我无法获取它。

//it gives label, title
System.out.println("z " + f.getToolbar().getComponentAt(0));

//it gives button, title command
System.out.println("zz" + f.getToolbar().getComponentAt(1));

//it gives no of component = 2
System.out.println("zzz" + f.getToolbar().getComponentCount());

为什么我获取不到工具栏的menuButton命令? ps 我已将命令行为设置到一边。

菜单按钮不是命令,不应直接操作。它具有特意抽象的独特行为。使用 getComponent(int) 是一种脆弱的方法,因为它依赖于可能会在没有任何警告的情况下突然改变的特定行为。

您需要考虑您感兴趣的用例并进行跟进。

例如:

  • 如果你想控制菜单图标,你可以通过 sideMenuImage & sideMenuPressImage
  • 如果您想设置菜单按钮的样式,您可以使用 MenuButton UIID