Cordova InAppBrowser加载Spinner for Android

时间:2015-08-10 21:28:19

标签: android ios cordova phonegap-plugins inappbrowser

我使用cordova和InAppBrowser构建了一个应用程序。我试图展示一个"加载微调器"在每一页。 在iOS中,它在我加载的每个页面上运行良好,但Android失败了。 在iOS上,我刚刚在CDVInappBrowser.m中编辑了self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]这一行并且正常工作。 Android有类似的功能吗?

这是我的代码:

       // Cordova is ready
        function onDeviceReady() {

            var ref = window.open("http://m.estadao.com.br/?load-all=true", "_blank", "location=no", "toolbar=no", "closebuttoncaption=a", "EnableViewPortScale=no");

            navigator.notification.activityStart("Loading", "Loading...");
            setTimeout(function(){
                navigator.notification.activityStop();
            }, 5000);
         }

3 个答案:

答案 0 :(得分:1)

检查此插件: https://github.com/Paldom/SpinnerDialog

在Android中为我工作。您应该使用此方法来显示带有标题和消息的微调器:

window.plugins.spinnerDialog.show("Loading","Loading...");

您的代码将是:

  function onDeviceReady() {

        var ref = window.open("http://m.estadao.com.br/?load-all=true", "_blank", "location=no", "toolbar=no", "closebuttoncaption=a", "EnableViewPortScale=no");

        window.plugins.spinnerDialog.show("Loading","Loading...");
        setTimeout(function(){
            window.plugins.spinnerDialog.hide();
        }, 5000);
  }

答案 1 :(得分:0)

Resvolvi dessa forma

// window.open示例

 // Wait for device API libraries to load
   document.addEventListener("deviceready", onDeviceReady, false);
   function onDeviceReady() {
    // external url
   // var ref = window.open(encodeURI('http://mfsom.com.br/'), '_blank', 'location=no','toolbar=no');
   //relative document
     ref = window.open('http://mfsom.com.br/','_self',',location=no');

ref.addEventListener('loadstart', loadstartCallback);
ref.addEventListener('loadstop', loadstopCallback);
ref.addEventListener('loadloaderror', loaderrorCallback);
ref.addEventListener('exit', exitCallback);

function loadstartCallback(event) {

    showSpinnerDialog();

}

function loadstopCallback(event) {
    hideSpinnerDialog();
}

function loaderrorCallback(error) {
console.log('Erro ao carregar: ' + error.message)

}

function exitCallback() {
console.log('O navegador está fechado...')

}

function showSpinnerDialog() {
navigator.notification.activityStart("Carregando..");
//$.mobile.loading("show");
}

function hideSpinnerDialog() {
navigator.notification.activityStop();
    //$.mobile.loading("hide");
}

// Handle the Cordova pause and resume events
document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener( 'resume', onResume.bind( this ), false );

// TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.

};

答案 2 :(得分:0)

由于这两个答案都使用了已弃用的activityStop(),因此请使用您自己的微调器,您可以在应用中使用该微调器来防止InAppBrowser出现空白的打开屏幕

使用InAppBrowser选项打开hidden=yes,随后在loadstop事件监听器中显示InAppBrowser。直到您可以展示您的自定义加载程序

var ref = window.open("http://m.estadao.com.br/?load-all=true", "_blank", "location=no,toolbar=no,closebuttoncaption=a,EnableViewPortScale=no,hidden=yes");
ref.addEventListener('loadstart', function() {
  showLoader();//`showLoader()` is your own loader function to show loader within your app
});
ref.addEventListener('loadstop', function() {
  ref.show();
  hideLoader();//`hideLoader()` is your own loader function to hide loader within your app
});