在CodenameOne中,什么会导致我的“后退”按钮不起作用(无法按下)?

时间:2018-08-18 21:04:42

标签: codenameone

TL / DR:无法再在模拟器或设备中按iOS上的Back命令软键(但在模拟器上,我可以按“ esc”以触发“后退”操作)。这曾经在较旧的版本中起作用。

详细信息: 在iOS上的我的beforeVideoScreen方法中(对于(旧)Gui Builder中内置的“视频屏幕”表单),以下代码在屏幕底部放置了“返回”按钮。由于某种原因,它最近停止在CN1库和插件的最新更新中工作(我使用的是插件4.4和最新的CN1库)。该按钮将无法再按下。

@Override
protected void beforeVideoScreen(Form f) {

    final Form vidForm = f;

    final Command backCommand = Command.create("Back", null, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            Log.p("Back pressed in Video screen");

            //stop the video playing by blanking the browser object
            browser.setPage("<html><body></body></html>", null);

            //remove the browser from the page before going back to deal with android "double-back" bug
            vidForm.removeComponent(browser);

            //add an image to make the blank screen look better as it slides out
            vidForm.addComponent(BorderLayout.CENTER, new Label(fetchResourceFile().getImage("SplashScreenLogo.jpg")));

            //perform the back operation - pop the video screen off the back stack
            back();
        }
    });
    f.removeAllCommands();

    f.addCommand(backCommand);

    f.setBackCommand(backCommand);

...

}

有什么想法可以防止后退按钮被按下吗?我尝试添加其他命令来查看它们是否可以被按下,但也不能被按下。

1 个答案:

答案 0 :(得分:0)

我没有使用所有表格切换到工具栏,而是采用了笨拙的解决方法。

我最初将“ CommandBehaviour”主题常量设置为“ Touch”,因为它提供了我想要的界面:屏幕底部的“ Back”按钮。

显然已弃用。

解决此问题的最简单方法是在“窗体”的BorderLayout的南窗格中手动添加一个“后退”按钮,并为其分配与BackCommand相同的命令

final Command backCommand = Command.create("Back", null, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent evt) {
        Log.p("Back pressed in Video screen");
        //stop the video playing by blanking the browser object
        browser.setPage("<html><body></body></html>", null);

        //remove the browser from the page before going back to deal with android "double-back" bug
        vidForm.removeComponent(browser);

        //add an image to make the blank screen look better as it slides out
        vidForm.addComponent(BorderLayout.CENTER, new Label(fetchResourceFile().getImage("SplashScreenLogo.jpg")));

        //perform the back operation - pop the video screen off the back stack
        back();
    }
});
f.removeAllCommands();
f.setBackCommand(backCommand);

Button backButton = new Button(backCommand);

f.addComponent(BorderLayout.SOUTH, backButton);
...