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

时间:2012-03-22 09:54:20

标签: 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,按钮的顺序是相反的。它以“Ok”然后“取消”而来。

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

iPhone Screenshot android Screenshot

欢迎所有建议:)

谢谢,

4 个答案:

答案 0 :(得分:2)

尝试使用以下解决方案:

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);

答案 1 :(得分:2)

这不是问题。你得到的是各自平台的原生行为。在iOS中,“取消”按钮将显示在左侧,而在Android中,您将在右侧显示。如果问题只是按钮索引,那么您可以在代码中处理它。但是你不能改变屏幕上按钮的顺序。

答案 2 :(得分:0)

我没有在iphone中试过这个。但是已经在android中尝试了这个。我没有遇到phonegap 1.4.1的任何问题。因此我建议你升级你的phonegap版本。您遇到的问题可能会在新版本中修复。 :)

答案 3 :(得分:0)

我有点迟了但是我遇到了同样的问题,不过我所做的就是改变它们,所以“取消”去了“好”,“好”去了“取消”。这对我有用。