• ionic android双击退出应用和物理返回按钮隐藏键盘的实现


    angular.module('starter', ['ionic', 'route', 'config', 'global', 'commonJs', 'ngCordova'])
        .run(['$ionicPlatform', '$rootScope', '$location', '$timeout', '$ionicHistory', 'CommonJs', '$cordovaToast','$cordovaKeyboard', function ($ionicPlatform, $rootScope, $location, $timeout, $ionicHistory,CommonJs,$cordovaToast,$cordovaKeyboard) {
            $ionicPlatform.ready(function () {
                // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
                if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
                    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
                }
                if (window.StatusBar) {
                    // org.apache.cordova.statusbar required
                    StatusBar.styleLightContent();
                }
            });
     
            //物理返回按钮控制&双击退出应用
            $ionicPlatform.registerBackButtonAction(function (e) {
                //判断处于哪个页面时双击退出
                if ($location.path() == '/tab/todoList' || $location.path() == '/tab/doneList' || $location.path() == '/tab/account'|| $location.path() == '/login') {
                    if ($rootScope.backButtonPressedOnceToExit) {
                        ionic.Platform.exitApp();
                    } else {
                        $rootScope.backButtonPressedOnceToExit = true;
                        $cordovaToast.showShortBottom('再按一次退出系统');
                        setTimeout(function () {
                            $rootScope.backButtonPressedOnceToExit = false;
                        }, 2000);
                    }
                }else if ($ionicHistory.backView()) {
                    if ($cordovaKeyboard.isVisible()) {
                        $cordovaKeyboard.close();
                    } else {
                        $ionicHistory.goBack();
                    }
                }
                else {
                    $rootScope.backButtonPressedOnceToExit = true;
                    $cordovaToast.showShortBottom('再按一次退出系统');
                    setTimeout(function () {
                        $rootScope.backButtonPressedOnceToExit = false;
                    }, 2000);
                }
                e.preventDefault();
                return false;
            }, 101);
     
        }]);

     转自:http://my.oschina.net/u/1416844/blog/490097

  • 相关阅读:
    API开放平台基于accessToken实现
    web记住我功能的实现
    SpringBoot整合AbstractRoutingDataSource实现读写分离
    手写简化版SpringBoot
    mybatisGenerator
    C程序编译执行过程
    用WaveX实现音频文件的录音
    java学习--数组
    Linux学习笔记--vim
    PHP常量总结
  • 原文地址:https://www.cnblogs.com/nikyxxx/p/5262609.html
Copyright © 2020-2023  润新知