如何在Webview Android中加载页面


how to load page in Webview android

>我有一个Android WebView应用程序,它显示了我的网站,我想知道是否有办法控制页面的加载状态,并放置"正在加载..."Web 视图中每个 HTML 页面的脚本,而且我也有 2 个问题,当我启动我的应用程序时,它会显示大约 4-5 秒的黑屏另一个是,当我的WebView加载时,它不会以正确的方式加载网页,但是当我重新加载时,它可以正常工作。谢谢你们

这是我的网站"主页"

<!doctype html>
<html>
<head>

<meta charset="utf-8">
<title>Eventi</title>
<link rel="stylesheet" type="text/css" href="CSS/stile.css">
<script src="JS/jquery-1.11.1.js.js"></script>
<script src="JS/func.js"></script>
<?php include ("PHP/phpfiles.php");?>

</head>
<body>
    <div id="navigation">
        <a href="eventi.php"> <div align="left" style="float:left;margin-left: 5%; margin-top:-1.5%;"><img src="IMG/reload.png" width="30" height="30"  alt=""/></div> </a>
        <a href="#" style="margin-left:-5.3%;"><img src="IMG/logo_navbar.png" width="300" height="30"  alt="Logo" class="logonavig"/></a>
        <div align="right" style="float:right;margin-right: 5%;"><img src="IMG/undo.png" width="10" height="11"  alt=""/></div>
    </div>
<!-- 
<? if ($_SESSION['FBID']): ?>
<p class="testobparty"><font color="#000000" > Benvenuto/a &nbsp; </font> <font color="#1D49A2" size="5px" style="font-weight:bold;"><? echo $_SESSION['FULLNAME']; ?></font></p>
<? else: ?>
<p class="testobparty"> <a href="LOGIN/1353/fbconfig.php" style="text-decoration:underline; color:#1D49A2; font-weight:bold; font-family:Impact, Haettenschweiler, 'Franklin Gothic Bold', 'Arial Black', sans-serif;"><img src="IMG/buttonfb3.png" height="40" width="300"> </a></p>
<? endif ?> --> <br> <br> <br>
         </div>
         </div>
                                          <? inserisci_div(); ?>




     <div id="footer"> © - 2014 <font color="#FFF">BParty by BParty Staff</font> All rights reserved | <a href="http://www.ask.fm/BPartyOfficial">ASK.FM</a> | <a href="https://www.facebook.com/people/BParty-Profilo/100007646898561">FACEBOOK</a> | <br> Icon made by <a href="http://www.icons8.com" title="Icons8"><font style="font-weight:200">Icons8</font></a> from <a href="http://www.flaticon.com" title="Flaticon"><font style="font-weight:200">www.flaticon.com</font></a> is licensed under <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0"><font style="font-weight:200">CC BY 3.0</font></a> 
</div>


</body>
</html>

我认为问题是我的JS文件

$(document).ready( function(){
 if ($(window).width() > 1001 && $(window).width() < 10000 ) 
    { 
     $("#menubar").css("font-size", ((($(window).height()*8)/100)));
     $(".fotoevento").css("height", ((($(window).height()*45)/100)));
     $(".fotoevento").css("width", ((($(window).height()*100)/100)));
      $(".pub").css("margin-left", ((($(window).height()*13)/100)));
      $(".testievento").css("font-size", ((($(window).width()*3)/100)));
      $("#footer").css("font-size", ((($(window).width()*3)/100)));

              //MOBILE
     $(".logonavig").css("height", ((($(window).height()*3)/100)));
     $(".logonavig").css("width", ((($(window).width()*19)/100)));
     }

 else if ($(window).width() < 1000) 
    { 
     $("#menubar").css("font-size", ((($(window).height()*3)/100)));
     $(".fotoevento").css("height", ((($(window).height()*35)/100)));
     $(".fotoevento").css("width", ((($(window).width()*90)/100)));
      $(".pub").css("margin-left", ((($(window).height()*13)/100)));
      $(".testievento").css("font-size", ((($(window).width()*5)/100)));
      $(".imamgineeventocompleta").css("margin-top", ((($(window).height()*9)/100)));
      $("#footer").css("font-size", ((($(window).width()*2.4)/100)));

      //MOBILE
     $(".logonavig").css("height", ((($(window).height()*3)/100)));
     $(".logonavig").css("width", ((($(window).width()*47)/100)));

     }
  else { 
          $("#menubar").css("font-size", ((($(window).height()*3)/100)));
          $(".fotoevento").css("height", ((($(window).height()*60)/100)));
          $(".fotoevento").css("width", ((($(window).height()*110)/100)));
          $(".pub").css("margin-left", ((($(window).height()*60)/100)));
              $(".testievento").css("font-size", ((($(window).width()*5)/100)));
              //MOBILE
     $(".logonavig").css("height", ((($(window).height()*3)/100)));
     $(".logonavig").css("width", ((($(window).width()*35)/100)));
        }

对于您的第一个问题,将 WebViewClient 添加到您的 Web 视图,并在以下代码中处理文本显示:

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    super.onPageStarted(view, url, favicon);
    //getActionBar().setTitle("Loading...");  for example
}
@Override
public void onPageFinished(WebView view, String url) {
    //getActionBar().setTitle("Loaded");  for example
}

对于 secound 问题,将 setContentView(R.layout.activity_loading); 紧跟在后面

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loading);

希望它有帮助...