android - PhoneGap 框架中 navigator.notification.confirm 中的按钮顺序

标签 android iphone cordova phonegap-plugins

我在我的 PhoneGap 应用程序中使用了以下代码。

        function registrationCallBack(button){
            if(button == 2) {
                window.location.href = "login.html";
            }
        }

   navigator.notification.confirm("Are you sure ?", registrationCallBack, "Confirmation", "Cancel, Ok");

按钮的顺序在 iPhone 中正确显示为“取消”和“确定”。 但对于 Android,按钮的顺序是相反的。它以“确定”的形式出现,然后是“取消”。

因此,按钮索引在回调方法中发生了变化。

iPhone Screenshot android Screenshot

欢迎所有建议:)

谢谢,

最佳答案

尝试使用以下解决方案:

function showConfirm(message, callback, buttonLabels, title){

    //Set default values if not specified by the user.
    buttonLabels = buttonLabels || 'OK,Cancel';

    title = title || "default title";

    //Use Cordova version of the confirm box if possible.
    if(navigator.notification && navigator.notification.confirm){

            var _callback = function(index){
                if(callback){
                    callback(index == 1);
                }
            };

            navigator.notification.confirm(
                message,      // message
                _callback,    // callback
                title,        // title
                buttonLabels  // buttonName
            );

    //Default to the usual JS confirm method.
    }else{
        invoke(callback, confirm(message));
    }
}

下面是您将如何使用它:

var message = "Would you like to proceed?";
var title = "Important Question";

//The first element of this list is the label for positive 
//confirmation i.e. Yes, OK, Proceed.
var buttonLabels = "Yes,No";

var callback = function(yes){
    if(yes){
        alert('Proceed');
    }else{
        alert('Do Not Proceed'); 
    }
};

showConfirm(message, callback, buttonLabels, title);

关于android - PhoneGap 框架中 navigator.notification.confirm 中的按钮顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9819851/

相关文章:

android - 如何镜像 TextView

iphone - Xcode 无法识别图像大小的变化

iphone - 如何在运行时在 iPhone sdk 中删除图像背景

sqlite - 如何离线创建Web sql数据库

javascript - AngularJS:存储失败的http请求并稍后再试

plugins - Phonegap 添加插件失败 (errno 34) */plugin.xml

android - 在 OpenGL android 中设置背景

android - 弹出验证 native 密码android

iphone - 静态库中的 Objective-C 类别

android - 向 NFC-V 中的特定内存块(位置)写入和读取多个值