【问题标题】:Codename One Back Command on left and Menu on Right左边的代号一后退命令和右边的菜单
【发布时间】:2016-04-24 02:27:36
【问题描述】:

我正在尝试在 Codename one 中创建一个应用程序,我想在屏幕顶部的右侧创建一个汉堡菜单并在左侧创建一个后退按钮,但无法让它工作我知道它可以在左侧有一个汉堡菜单,在右侧有一个按钮的情况下完成。我拍了一张我想要的照片。后退按钮是在绘画中添加的,而不是通过代码添加的。 Picture of app example

下面是我用来获取右侧菜单的代码。

public class MainForm {
    public static Form mainForm;
    Command cmd_back, cmd_AboutTheApp;
    private enum SideMenuMode {
        SIDE, RIGHT_SIDE {
            public String getCommandHint() {
                return SideMenuBar.COMMAND_PLACEMENT_VALUE_RIGHT;
            }
        };

        public String getCommandHint() {
            return null;
        }
        public void updateCommand(Command c) {
            String h = getCommandHint();
            if(h == null) {
                return;
            }
            c.putClientProperty(SideMenuBar.COMMAND_PLACEMENT_KEY, h);
        }
    };
    SideMenuMode mode = SideMenuMode.RIGHT_SIDE;

    public void init(Object context) {
        theme = UIManager.initFirstTheme("/theme");
        UIManager.getInstance().setThemeProps(theme.getTheme theme.getThemeResourceNames()[0]));
        UIManager.getInstance().getLookAndFeel().setMenuBarClass(SideMenuBar.class);
        Display.getInstance().setCommandBehavior(Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION);
    }

    public void start() {
        if(mainForm != null){
            mainForm.show();
            return;
        }
        mainForm = new Form();
        mainForm.setTitleComponent(title);
        mainForm.setLayout(new BorderLayout());
        addCommands(mainForm);
    }
    private void addCommands(Form f){
        cmd_Back = new Command("Back");
        final Button btn_Back = new Button("Back");
        cmd_Back.putClientProperty("TitleCommand", btn_Back);
        btn_BackButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                //do some thing
            }
        });
        cmd_AboutTheApp = new Command("About the app");
        final Button btn_AboutTheApp = new Button("About the app");
        cmd_AboutTheApp.putClientProperty("SideComponent", btn_AboutTheApp);
        btn_AboutTheApp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                //do some thing
            }
        });
        mode.updateCommand(cmd_Back);
        f.addCommand(cmd_Back);

        mode.updateCommand(cmd_AboutTheApp);
        f.addCommand(cmd_AboutTheApp);
    }
}

如果我将后退按钮添加到 AboutTheApp 按钮之后,则后退按钮会显示在屏幕的右侧,但也会显示在菜单的右侧,菜单也在右侧。我尝试了很多不同的方法,但似乎都没有奏效

【问题讨论】:

    标签: codenameone hamburger-menu


    【解决方案1】:

    我们在 SideMenuBar 中支持右侧菜单栏,但在 Toolbar API 中不支持。我们支持将组件/命令放置在 Toolbar API 中标题区域的左侧/右侧,但不支持在 SideMenuBar 中。

    我想解决方案是在Toolbar API 中添加对右侧菜单栏的支持,但我不确定这种更改的复杂性是什么。

    我建议在问题跟踪器中提交 RFE 来询问此问题,但可能不会很快,因为我们现在正在关闭 3.3 的功能。

    【讨论】:

    • 这方面有更新吗?目前有没有办法把侧边菜单放在右边?
    • 是和不是。我们使用顶部侧菜单栏 API 重写了侧菜单栏。这是一个完整的重写,有望使右侧菜单栏更加逼真。现在我们没有右侧菜单栏支持或 RTL 支持,我不确定是否有问题,如果没有应该有
    【解决方案2】:

    我有一个应用程序可以做到这一点。在 Google Play(或 App Store)中搜索“Torquepower Diesel Cummins Engine”应用。

    1. 在主题Constants中我设置了自己的rightSideMenuImage和rightSideMenuPressImage,但是默认的汉堡菜单可能适合你。

    2. 在每个表单的 beforeXXXX 上,我执行以下操作:

      super.beforePartNumberForm(f);
      
      Toolbar tb = createToolbar(f);
      
      createBackCommand(f, tb);
      addHelpX(tb);
      addViewCartX(tb);
      addCallTorquepowerX(tb);
      addReverseSwipe(f);
      
    3. 创建工具栏

      Toolbar createToolbar(Form f) {
      
          Toolbar tb = new Toolbar();
          f.setToolBar(tb);
      
          Label l = new Label();
          l.setIcon(res.getImage("tpd_logoZZ.png"));
      
          tb.setTitleComponent(l);
      
          return tb;
      }
      
    4. 创建返回按钮

      void createBackCommand(Form f, Toolbar tb) {
      
          Command c = new Command("") {
              @Override
              public void actionPerformed(ActionEvent evt) {
                  back();
              }
          };
      
          c.setIcon(res.getImage("black_left_arrow-512.png"));
          c.setPressedIcon(res.getImage("grey_left_arrow-512.png"));
      
          // MUST set this before adding to toolbar, else get null pointer
          f.setBackCommand(c);
      
          tb.addCommandToLeftBar(c);
      }
      
    5. 在侧边菜单中添加任何需要的命令

      void addHelpX(Toolbar tb) {
          Command c = new Command("Help") {
              @Override
              public void actionPerformed(ActionEvent evt) {
                  showForm("HelpForm", null);
              }
          };
      
          c.putClientProperty(SideMenuBar.COMMAND_PLACEMENT_KEY, SideMenuBar.COMMAND_PLACEMENT_VALUE_RIGHT);
          c.putClientProperty("SideComponent", new SideMenuItem(fetchResourceFile(), c.toString(), "very_basic_about.png"));
          c.putClientProperty("Actionable", Boolean.TRUE);
      
          tb.addCommandToSideMenu(c);
      
      }
      

    我使用自己的 SideMenuItem:

    public class SideMenuItem extends Button {
        SideMenuItem() {
            this("");
        }
    
        SideMenuItem(String s) {
            super(s);
            setUIID("SideMenuItem");
            int h = Display.getInstance().convertToPixels(8, false);
            setPreferredH(h);
        }
    
        SideMenuItem(Resources res, String s, String icon) {
            super();
            setIcon(res.getImage(icon));
            setText(s);
            setUIID("SideMenuItem");
            int h = Display.getInstance().convertToPixels(8, false);
            setPreferredH(h);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 2014-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多