其实就是自定义一个启动页面,不顾完全可以不用这么做,MainActivity就可以充当启动页面来做,这个是官方的例子就顺便学习一下。同时这里也有延迟加载的例子。
index.html
MainActivity.java
index.html
- <!DOCTYPE html>
- <html>
- <head>
- <title>Splashscreen Example</title>
- <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
- <script type="text/javascript" charset="utf-8">
- // Wait for Cordova to load
- //
- document.addEventListener("deviceready", onDeviceReady, false);
- // Cordova is ready
- //
- function onDeviceReady() {
- //navigator.splashscreen.show();
- navigator.splashscreen.hide();
- }
- </script>
- </head>
- <body>
- <h1>Example</h1>
- </body>
- </html>
MainActivity.java
- package com.fanfq.phonegap.splashscreen;
- import org.apache.cordova.DroidGap;
- import android.os.Bundle;
- public class MainActivity extends DroidGap {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // The first line 'super.setIntegerProperty' sets the image to be
- // displayed as the splashscreen. If you have named your image anything
- // other than splash.png you will have to modify this line. The second
- // line is the normal 'super.loadUrl' line but it has a second parameter
- // which is the timeout value for the splash screen. In this example the
- // splash screen will display for 10 seconds. If you want to dismiss the
- // splash screen once you get the "deviceready" event you should call
- // the navigator.splashscreen.hide() method.
- super.setIntegerProperty("splashscreen", R.drawable.splash);
- super.loadUrl("file:///android_asset/www/index.html", 10000);
- }
- }