简体   繁体   English

加载Phonegap网站后,在Android上隐藏启动屏幕

[英]Hide splash screen on android once phonegap site has loaded

I have a website that uses media queries to look good on mobiles, I wrapped this up in phonegap so I can have it as an application too. 我有一个网站,该网站使用媒体查询在手机上看起来不错,我将其包装在phonegap中,因此也可以将其作为应用程序使用。 I have set super.loadUrl to my site and this works, I also have a working splash screen that I want to keep up until the site has loaded. 我已经将super.loadUrl设置为我的网站,并且可以正常工作,我还拥有一个正常的启动画面,我想一直保持该画面直到网站加载完毕。 I came across this blog post and followed the instructions. 我碰到了这篇博客文章,并按照说明进行操作。 It works if I am super.loadUrl to index.html (the app homepage) but not if I loadUrl of my actual site. 如果我是super.loadUrl到index.html(应用程序主页),则可以使用,但如果我是实际站点的loadUrl,则无法使用。

Splash screen code (main java file) 启动画面代码(主Java文件)

super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("My External Site Url", 20000);

Index.html code (this works if i loadUrl to it, but I want to loadUrl to my site) Index.html代码(如果我将loadUrl加载到我的网站,则可以使用该代码)

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    navigator.splashscreen.hide();
}

However, when I use the above code (and include cordova.js) in my external html file, it doesn't recognise onDeviceReady, so the splash screen doesn't hide itself, and I'm stuck waiting 20 seconds. 但是,当我在外部html文件中使用上述代码(并包括cordova.js)时,它无法识别onDeviceReady,因此初始屏幕不会隐藏起来,并且我不得不等待20秒。

Am I missing something? 我想念什么吗? Am I even allowed to use onDeviceReady from an external html file (eg one that is not build into the app) or should this work and I am just referencing cordova wrong? 我是否甚至可以从外部html文件(例如,未内置于应用程序的html文件)中使用onDeviceReady还是应该工作,而我只是引用了cordova错误?

It turns out an old include of prototype.js was messing this up. 事实证明,prototype.js的旧内容搞砸了这一点。 Once I removed that it works awesomely. 一旦我删除它,它就很棒。

For future people the errors I got were: 对于未来的人,我得到的错误是:

  • App doesn't react to touch, input buttons and hyperlinks can't be used. 应用对触摸没有反应,无法使用输入按钮和超链接。
  • If you press-hold on an input, hyperlink etc it got the orange focus box, but never took me to the link or activated the input button (cursor or keyboard) 如果您按住输入,超链接等按钮,它将显示橙色的焦点框,但从不带我进入链接或激活输入按钮(光标或键盘)
  • Prototype stopped me getting deviceready at any point, but no JS errors were thrown (except IE not liking addEventListener) 原型在任何时候都使我无法准备就绪,但是没有引发JS错误(IE不喜欢addEventListener)

Try doing this: 尝试这样做:

<script> 
function init() {
    document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
    navigator.splashscreen.hide();
}
</script>
<body onload="init()">

Although since you are using jQuery you may want to change it to: 尽管由于您使用的是jQuery,但您可能希望将其更改为:

$(document).ready(function() {
  document.addEventListener("deviceready", onDeviceReady, false);
});

Frist add the splashscreen plugin as follow: Frist添加启动画面插件,如下所示:

$ phonegap plugin add org.apache.cordova.splashscreen

Second build the project,"splashscreen.js" will be merged into the "phonegap.js" 第二个构建项目,“ splashscreen.js”将合并到“ phonegap.js”中

$ phonegap local build

Good Luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM