停止退出后退按钮Android在PhoneGap - 构建 [英] Stop Exit on Back Button Android in PhoneGap - Build

查看:96
本文介绍了停止退出后退按钮Android在PhoneGap - 构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 PhoneGap Build 在线构建我的应用程序。
我想改变Back Button的默认行为

I'm building my application through PhoneGap Build online. I want to change the default behavior of Back Button

$(document).ready(function(e) {
    document.addEventListener("backbutton", onBackKeyDown, false);
});

function onBackKeyDown(){
    alert('back');
    return false;
}

它不工作我已经搜索解决方案。但是,他们都显示更改PhoneGap库中的 java 代码,这不是我的情况。我以 .zip 格式用 config.xml 提交我的应用程序。

Its not working I've searched for solution. But, they all showing to change the java codes in PhoneGap library, which is not in my case. I'm submitting my application in a .zip format with config.xml inside.

config.xml

Is it possible with config.xml?

推荐答案

首先,我做错了@Mejo指出的,谢谢。

First of all I did wrong as pointed by @Mejo, Thanks. Here is the solution to the problem.

第1步:包含脚本到HTML在应用程序zip中不需要它,包括<通过PhoneGap Build自动地

Step 1: Include Script to HTML don't need it physically within application zip, as included automatically by PhoneGap Build

< script src =cordova.js>< / script& code>或< script src =phonegap.js>< / script> 任何一个都可以正常工作。

<script src="cordova.js"></script> or <script src="phonegap.js"></script> any of them will work fine.

步骤2:将此脚本添加到脚本以获取设备就绪

Step 2: Add this to script to get device ready call:

document.addEventListener("deviceready", onDeviceReady, false);

第3步:添加事件侦听器 返回按钮,并将您的代码添加到该调用中:

Step 3: Add event listener to back button and add your code to that call:

function onDeviceReady(){
    document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown(){
    alert('back');
    return false;
}

现在,如果您不设置 minSDK 到应用程序

Still now it will not work if you don't set preference of minSDK to application by config.xml

步骤4: config.xml

Step 4: Add this to preference region of config.xml

< preference name =android-minSdkVersionvalue =5/& / code>

<preference name="android-minSdkVersion" value="5" />

供参考: http:// community.phonegap.com/nitobi/topics/how_to_handle_back_button_in_android

这篇关于停止退出后退按钮Android在PhoneGap - 构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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