如何隐藏PhoneGap Android SplashScreen

How to hide PhoneGap Android SplashScreen?

本文关键字:PhoneGap Android SplashScreen 隐藏 何隐藏      更新时间:2023-11-10

我已经做了一个简单的应用程序来获取坐标,它运行得很好,但我在启动应用程序时遇到了一个问题,在启动index.html之前会出现一个空白黑屏。我如何在启动应用程序时删除那个空白黑屏。我使用的是cordova-2.4.0.js

我的index.html是

<!DOCTYPE html>
<html>
  <head>
    <title>Device Properties Example</title>
    <script type="text/javascript" charset="utf-8" src="cordova-2.4.0.js"></script>
    <script type="text/javascript" charset="utf-8">
    document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
      // cordova.exec(null, null, "SplashScreen", "hide", []);
      navigator.splashscreen.hide();
    }
    </script>
    <style>
    h3 {
    left: 0;
    line-height: 50px;
    margin-top: -100px;
    position: absolute;
    text-align: center;
    top: 60%;
    width: 100%;
    }
    body
    {
    background-color:#D7EBFF;
    }
    header
    {
    background-color:#C3E1FF;
    }
    </style>
    <script type="text/javascript">
        function showLocation(position)
         {
          var latitude = position.coords.latitude;
          var longitude = position.coords.longitude;
          document.getElementById("demo").innerHTML="Latitude : " + latitude + "</br> Longitude: " + longitude ;
          //alert("Latitude : " + latitude + " Longitude: " + longitude);
         }
        function errorHandler(err)
         {
          if(err.code == 1)
           {
            alert("Error: Access is denied!");
           }
          else if( err.code == 2)
          {
            alert("Error: Position is unavailable!");
           }
        }
        function getLocation()
        {
          var watchID = null;
          if(navigator.geolocation)
           {
              var options = { timeout: 5000, enableHighAccuracy: true };
              watchID = navigator.geolocation.watchPosition(showLocation, errorHandler, options);
           }
           else
           {
              alert("Sorry, does not support geolocation!");
           }
        }
        </script>
  </head>
        <body onload="getLocation();">
        <header>
        <center>
        <h2>Gps Coordinates </h2>
        </center>
        </header>
         <h3>
             <p id="demo">Searching for GPS..</p>
         </h3>
        </body>
  </html>

我的MainActivity.java类是

public class MainActivity extends DroidGap {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       super.loadUrl("file:///android_asset/WWW/index.html");
        //setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

我已经尝试在加载index.html时删除那个空白屏幕,但我不知道怎么做。我想是因为设备正在加载应用程序。

你能做的是创建自己的启动屏幕吗?通过以下链接,您将了解如何创建自己的启动屏幕:http://docs.phonegap.com/en/2.2.0/cordova_splashscreen_splashscreen.md.html

希望能对你有所帮助。