Toolbar and back command issues

71 views
Skip to first unread message

pejo...@gmail.com

unread,
May 24, 2016, 3:41:44 AM5/24/16
to CodenameOne Discussions
Hi!

Yesterday I suddenly got some issues with the toolbar and back command in my app. I guess it has to do with the changes you recently did  to the toolbar api. To describe the problem, just suppose that I have a app (old GUI-builder app) consisting of 2 forms. The problem occurs when I navigate to form2. 

What I want (and had until yesterday) is that the titlearea of form2 just shows a back arrow (on both Android and iOS) and the title of the form.

 

What i got from yesterday and forward is that a hamburger menu automatically appears in form2, plus a back arrow, plus my back arrow.



Before I used this code to add a back arrow (back command) to form2.
@Override
    protected void beforeForm2(Form f) {
        // Back button in title area
        Style s = UIManager.getInstance().getComponentStyle("TitleCommand");
        FontImage icon = FontImage.createMaterial(FontImage.MATERIAL_NAVIGATE_BEFORE, s);
        //f.getToolbar().addCommandToLeftBar("", icon, (e) -> showForm("Main", f.getBackCommand()));
    }


So how do I remove the hamburger menu from form2? 

I tested to use "f.removeAllCommands();" in the beforeForm2 method and that removes the hamburger menu but as soon as I try to add some back command I got two back arrows.

One strange thing is that if I create a new project my old code works as before as long as I only compile it locally. As soon as I send a Android build to the buildserver then the new thing happens.
 















If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans
Desktop OS: Linux Mint
Simulator
Device
Message has been deleted

pejo...@gmail.com

unread,
May 24, 2016, 12:04:28 PM5/24/16
to CodenameOne Discussions, pejo...@gmail.com
Never mind!

I found the solution from a similar question at stackowerflow.

I had to add the toolbar manually for the form2 like this:

@Override
protected void beforeForm2(Form f) {
    f.setToolbar(new Toolbar()); 
    f.setTitle("Form2"); 
    Style s = UIManager.getInstance().getComponentStyle("TitleCommand");
    FontImage icon = FontImage.createMaterial(FontImage.MATERIAL_NAVIGATE_BEFORE, s);
   f.getToolbar().addCommandToLeftBar("", icon, (e) -> showForm("Main", f.getBackCommand())); 
}

Does'nt "Toolbar.setGlobalToolbar(true);" work anymore?


Shai Almog

unread,
May 25, 2016, 1:01:47 AM5/25/16
to CodenameOne Discussions, pejo...@gmail.com
There is a regression there which we've fixed already. It will be in this Friday release.

pejo...@gmail.com

unread,
May 25, 2016, 2:18:03 AM5/25/16
to CodenameOne Discussions, pejo...@gmail.com
Ok great! I'll wait for that fix then. 

I noticed that the android hardware back-button does'n work with the solution that I tried.

Shai Almog

unread,
May 26, 2016, 12:14:43 AM5/26/16
to CodenameOne Discussions, pejo...@gmail.com
Did you override the setBackCommand method?

pejo...@gmail.com

unread,
May 26, 2016, 2:37:10 AM5/26/16
to CodenameOne Discussions, pejo...@gmail.com
Ok I have fixed the override and now it's working, thanks! 

Here is the code if anyone else is looking for the same solution.

// Added this to the statemachine class
 @Override
    protected void setBackCommand(Form f, Command backCommand) {    // added this override 20160526 to fix bug in navigation
        if(shouldAddBackCommandToMenu()) {
            f.addCommand(backCommand, f.getCommandCount());
        }
        f.setBackCommand(backCommand);
    }


// And this is what I have in Form2's before method
  @Override
    protected void beforeForm2(Form f) {
        
        f.removeAllCommands();            
        
        // Back button in title area
        Style s = UIManager.getInstance().getComponentStyle("TitleCommand");
        FontImage icon = FontImage.createMaterial(FontImage.MATERIAL_NAVIGATE_BEFORE, s);
        f.getToolbar().addCommandToLeftBar("", icon, (e) -> showForm("Main", f.getBackCommand()));
    
    }





Reply all
Reply to author
Forward
0 new messages