听侧边菜单/汉堡菜单点击事件

Listen to side menu / hamburger menu clicked event

我想检测侧边菜单或汉堡菜单何时被点击。

这是一个不起作用的准系统 hello world 项目的代码:

    Form hi = new Form("Hi World");
    Toolbar bar = new Toolbar();
    hi.setToolbar(bar);
    bar.addCommandToSideMenu(new Command("test 1"));
    bar.addCommandToSideMenu(new Command("test 2"));
    hi.addComponent(new Label("Hi World"));

    bar.getMenuBar().addPointerPressedListener(new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent evt) {
           System.out.println("Side menu or Hamburner Menu is clicked");
        }
    });
    hi.show();

我希望当我单击侧面菜单或汉堡菜单时看到打印的字符串。但事实并非如此。

如何监听汉堡包菜单的点击事件。

谢谢,

3lix

由于工具栏只是窗体顶部的 BorderLayout 容器,您可以找到侧边菜单按钮并在其上添加侦听器。

Button sideBtn = (Button)((BorderLayout)bar.getLayout()).getEast();

请注意,这是一个未记录的 API,因此将来可能会中断,侧边按钮出于某种原因没有故意暴露,请重新考虑您正在尝试做什么。

另一种方法是禁用侧面菜单图标并像我们在此模板中所做的那样自己添加按钮:http://www.codenameone.com/blog/template-mobile-material-screens-ui-kit.html