简体   繁体   English

Onsen UI:返回和菜单按钮

[英]Onsen UI: Back and Menu Button

The mobile app is Onsen UI based, I'm trying to manage both Android's Back and Menu Button.移动应用程序基于 Onsen UI,我正在尝试管理 Android 的返回和菜单按钮。 So my question is split into 2.所以我的问题分为2个。

First how to slide the app menu when the use clicks on device's menu button (especially Samsung)?首先如何在用户点击设备的菜单按钮(尤其是三星)时滑动应用程序菜单?

The second issue is about the Mobile Device Back button (hardware) when clicking on it, it exists the application while it should return to homepage and if on homepage the client should click twice to exist.第二个问题是关于移动设备返回按钮(硬件),当点击它时,它存在应用程序,而它应该返回主页,如果在主页上,客户端应该单击两次以存在。

I believe the Onsen team answered your question on their forums regarding the backbutton, but for others here are some resources:我相信 Onsen 团队在他们的论坛上回答了您关于后退按钮的问题,但对于其他人,这里有一些资源:

backbutton with Onsen simply issues popPage.带有 Onsen 的后退按钮只是发出 popPage。 If there is not a page to pop, it will exit the app.如果没有要弹出的页面,它将退出应用程序。 For more information on controlling that behavior, see this:有关控制该行为的更多信息,请参阅:

https://onsen.io/guide/overview.html#HandlingBackButton https://onsen.io/guide/overview.html#HandlingBackButton

ons.setDefaultDeviceBackButtonListener(function() {
  if (navigator.notification.confirm("Are you sure to close the app?",
    function(index) {
      if (index === 1) { // OK button
        navigator.app.exitApp(); // Close the app
      }
    }
  ));
});

For the menu button, you just need to add an event listener:对于菜单按钮,你只需要添加一个事件监听器:

document.addEventListener("menubutton", onMenuKeyDown, false);

function onMenuKeyDown() {
    // Handle the back button
}

https://cordova.apache.org/docs/en/latest/cordova/events/events.menubutton.html https://cordova.apache.org/docs/en/latest/cordova/events/events.menubutton.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM