javascript - phonegap的splashscreen有什么作用呢?
大家讲道理
大家讲道理 2017-04-10 12:46:36
0
1
879

phonegap的splashscreen API有两个方法,一个是show:显示启动画面,一个是hide:隐藏启动页面。 我写了一段测试代码:

<button id="showBtn">显示启动画面</button>
<button id="hideBtn">隐藏启动画面</button>
<p>测试是否中断了程序运行 <b id="num"></b></p>
<script>
    document.addEventListener('deviceready', function(){
        var i = 0;
        setInterval(function(){
            num.innerHTML = ++i;
        },1000);
        showBtn.onclick = function(){
            navigator.splashscreen.show();
        };
        hideBtn.onclick = function(){
            navigator.splashscreen.hide();
        };
    }, function(){});
</script>

但始终无法明白这个API有何用呢?求解

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

Antworte allen(1)
黄舟

因为页面通过phonegap(内部是webview)载入网页需要时间,这个时候网页会白屏,不好看。所以也可以用一个splash,也就是应用启动后出现一张全屏的图片,这样当页面加载完毕后,图片消息,网页也加载完毕了。其实这个API一般我不怎么用。因为完全可以在在onCreate方法中调用如下代码:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setIntegerProperty("splashscreen", R.drawable.splash);
        // 3s后splash关闭
        super.loadUrl("file:///android_asset/www/index.html", 3000);
    }
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage