如何控制android backbutton路由? [英] How to control android backbutton routes?

查看:85
本文介绍了如何控制android backbutton路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Onsen中的默认设置是当按下设备后退按钮时,应用程序将关闭/退出.有什么方法可以控制Onsen中的内容,使其也模仿ons-navigator的操作/页面历史记录?

The default in Onsen is that the app closes/exits when the device backbutton is pressed. Is there any way to control that in Onsen to also mimic the ons-navigator action/page history?

谢谢!

推荐答案

对于PhoneGap/Cordova,按下后退按钮时会触发后退按钮事件. 因此,您可以设置事件处理程序.

In case of PhoneGap/Cordova, backbutton event is fired when the backbutton is pressed. Therefore, you can set the eventhandler s.t.

document.addEventListener("backbutton", onBackKeyDown, false);

在事件处理程序功能中,您可以通过获取导航器作用域s.t来调用导航器的popPage方法.

In eventhandler function, you can call popPage method of navigator by obtaining the navigator scope s.t.

function onBackKeyDown() {
    // Handle the back button
    alert("Backbutton is pressed!");
    var element = document.querySelector( ".navigator-container");
    var scope = angular.element( element ).scope();
    scope.popPage();
}

如果您使用的是Monaca,则是基于Cordova的混合应用程序框架,即backbutton事件 不被解雇.相反,您可以使用.ui文件,其中在其中定义了Backbutton事件.

If you are using Monaca, the hybrid application framework based on Cordova, the backbutton event is not fired. Instead that you can use the .ui file in which the Backbutton event is defined s.t.

{
    "event" : {
        "onTapBackButton" : "onBackKeyDown();"
    }
}

这篇关于如何控制android backbutton路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆