android - 如何在页面显示前加载phonegap中的css?

标签 android cordova

我正在创建一个 Phonegap 应用程序。在我的应用程序中,我为“Android”和“ios”使用了不同的 css,所以只有当它是 android 时我才需要加载 css。以下代码工作正常,但最初页面加载时没有 css,然后在 phonegap 加载后加载我的 css,每次我显示该页面时都会显示一个跳舞页面(即)在页面显示后加载 css。任何人都可以帮助加载页面显示之前的 css,但前提是它是 android 平台。

     <script type="text/javascript" >
     var string;
     // Wait for PhoneGap to load 
     document.addEventListener("deviceready", onDeviceReady, false);

     // PhoneGap is loaded and it is now safe to make calls PhoneGap methods
     function onDeviceReady() 
     {
       check_img();
    }

   function check_img() 
   {
     string = device.platform;
    if(string=="Android")
    {
      var head  = document.getElementsByTagName('head')[0];
      var link  = document.createElement('link');
      //link.id   = cssId;
      link.rel  = 'stylesheet';
      link.type = 'text/css';
      link.href = 'css/style.css';
      //link.media = 'all';
      head.appendChild(link);
    }
    } 
    </script>

最佳答案

我在这里找到了答案。 http://simonmacdonald.blogspot.in/2012/04/phonegap-android-splashscreen-just-got.html

当你设置启动画面时,你在 mainactivity.java 文件中执行以下操作

    super.setIntegerProperty("splashscreen", R.drawable.splash);
    super.loadUrl("file:///android_asset/www/index.html", 10000);

这会显示启动画面 10 秒,然后加载 index.html 页面。注意我当时说的。是的,显示启动画面是阻塞调用是正确的。在显示初始屏幕时,您的 .html/.js/.css 未在后台加载。好吧,这一切都在改变,因此您的启动画面显示在一个线程上,而您的应用程序在另一个线程的启动画面下加载。最好的事情是您不需要对代码进行任何更改。像往常一样继续调用启动画面。

关于android - 如何在页面显示前加载phonegap中的css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12275123/

相关文章:

android - 自定义 ArrayAdapter onLongClickListener

android - 在 Android 6.0 中获取 MAC 地址

android - ionic 框架移动应用程序大小问题

cordova - Windows Cordova 应用程序 : An app can’t load remote web content in the local context

node.js - Phonegap : two kinds of installations, 有什么区别?

android - 如何在 Android 的应用程序中显示文件预览和打开文件?

android - 通过电子邮件发送 WhatsApp 聊天时,如何让我的 Android 应用程序出现在应用程序选择器中?

jquery - 在大结果上使用 phonegap 自动完成 jQuery

iOS - 从外部类引用事件 Storyboard View Controller

android - 如何在android中的其他两个 View 之间垂直放置一个 View ?