问题
after having added a command to the Toolbar using addCommandToRightBar(Command), I want to remove or hide the command again (e.g. when I select/unselect on a specific tab in Tabs). In the SideMenuBar there is removeCommand(Command) for this, but I can't figure out how to do the same for Toolbar. Any suggestions how I can achieve this? Thanks
回答1:
removeCommand works but you should remember to revalidate()
:
Toolbar.setGlobalToolbar(true);
Form hi = new Form("Bar");
Command cmd = hi.getToolbar().addCommandToRightBar("Bla", null, (e) -> Log.p("Bla"));
hi.getToolbar().addCommandToLeftBar("Remove", null, (e) -> {
hi.removeCommand(cmd);
hi.revalidate();
});
hi.show();
来源:https://stackoverflow.com/questions/36293862/how-to-remove-a-command-added-to-the-toolbar-using-addcommandtorightbarcommand