【问题标题】:how to load page in Webview android如何在 Webview android 中加载页面
【发布时间】:2015-02-25 21:16:03
【问题描述】:

我有一个 android webview 应用程序,可以显示我的网站, 我想知道是否有办法控制页面的加载状态,并为 webview 中的每个 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)));
        }

【问题讨论】:

    标签: php android web webview


    【解决方案1】:

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

    @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
    }
    

    对于第二个问题,把 setContentView(R.layout.activity_loading);直接在

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

    希望对你有帮助...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-03
      相关资源
      最近更新 更多