1. 程式人生 > >ionic2/3註冊安卓返回

ionic2/3註冊安卓返回

bsp lose npr else portal overlay smi ast iss

如果使用了

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註冊安卓返回