Android “back” button vs Desktop “Escape” key

余生长醉 提交于 2019-12-17 21:12:18

问题


I am writing an app using JavafxPorts that I am planning on running on both Android and Desktop (PC).

I am trying to keep my code as generic as possible.

My question is... how can I support both the "back" button on Android and have it be equivalent to the "Escape" key on PC?

Basically I want to bring up the menu when the back button is pressed on Android or if the Escape key is pressed on PC.

Thanks!


回答1:


JavaFXPorts already has support for the back button on Android: it is mapped to the Escape key.

You can also use Gluon Charm Down, an OSS project that will let you easily find out about the platform you are running.

public void start(Stage primaryStage) {
    Scene = new Scene(...);

    scene.addEventHandler(KeyEvent.KEY_RELEASED, e -> {
        if (KeyCode.ESCAPE.equals(e.getCode())) {
            if (JavaFXPlatform.isAndroid()) {
                // bring up the menu or other Android stuff
            } else {
                // bring up the menu or other Desktop stuff
            }
        });
    }
}


来源:https://stackoverflow.com/questions/36302294/android-back-button-vs-desktop-escape-key

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!