ionic2/3注册安卓返回
Posted 栴檀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ionic2/3注册安卓返回相关的知识,希望对你有一定的参考价值。
如果使用了
this.app.getRootNav().push()以及this.navCtrl.push();
则在注册安卓返回键的时候
registerBackButtonAction() {
if (!this.nativeService.isandroid()) {
return;
}
this.platform.registerBackButtonAction(() => {
if (this.keyboard.isOpen()) {//如果键盘开启则隐藏键盘
this.keyboard.close();
return;
}
//点击返回按钮隐藏toast或loading或Overlay
this.ionicApp._toastPortal.getActive() ||this.ionicApp._loadingPortal.getActive()|| this.ionicApp._overlayPortal.getActive();
//隐藏modal
let activePortal = this.ionicApp._modalPortal.getActive();
if (activePortal) {
activePortal.dismiss();
return;
}
//页面返回
if(this.app.getRootNav().canGoBack()){
//this.showExit() this.nativeService.minimize()
return this.app.goBack()
}else{
return this.showExit();
}
}, 10);
}
//双击退出提示框
showExit() {
if (this.backButtonPressed) { //当触发标志为true时,即2秒内双击返回按键则退出APP
this.platform.exitApp();
} else {
this.nativeService.showToast(‘再按一次退出应用‘);
this.backButtonPressed = true;
setTimeout(() => { //2秒内没有再次点击返回则将触发标志标记为false
this.backButtonPressed = false;
}, 2000)
}
}
以上是关于ionic2/3注册安卓返回的主要内容,如果未能解决你的问题,请参考以下文章