代号为Android Sidemenu

时间:2015-12-07 10:32:16

标签: codenameone

我正在尝试实施Android风格的侧边菜单,而且在添加sideCommands之前我在顶部和标签下方实现圆形图标时遇到问题。

我该如何实现?

1 个答案:

答案 0 :(得分:2)

您可以使用工具栏API,它允许您将组件添加到Sidemenu。

查看Flickr demo

您应该使用tool.addCommandToSideMenu(Command)

而不是tool.addComponentToSideMenu(yourComponent, CommandToPerform)

示例:

@Override
protected void beforeMain(Form f) {
    //Store your commands before setting toolbar
    List<Command> cmds = new ArrayList();
    for (int i = 0; i < f.getCommandCount(); i++) {
        cmds.add(f.getCommand(i));
    }
    Toolbar toolbar = new Toolbar();
    f.setToolBar(toolbar);
    Label lblTitle = new Label("My Form", "Title");
    lblTitle.setEndsWith3Points(false);
    toolbar.setTitleComponent(lblTitle);

    // Use your stored commands after setting toolbar
    for (Command cmd : cmds) {
        toolbar.addCommandToSideMenu(cmd);
    }

    Container CustomContainer = ...
    toolbar.addComponentToSideMenu(CustomContainer, new Command("") {

        @Override
        public void actionPerformed(ActionEvent evt) {
            //What CustomContainer should do (if any)
        }
    });
    f.revalidate();
}