在Android应用程序的webview中加载URL时启动屏幕

我有一个应用程序,它有2个活动,第一个启动第二个将URL加载到webview中。

它工作正常,但是当url加载时,webview显示为空…然后我想制作一个启animation面或类似的东西,在url加载时显示它,我在新的活动中这样做,但我不知道我知道如果在加载url时我可以做什么来关闭第三项活动…请有人帮助我吗?

这是我的代码……谢谢!

public class Visor extends Activity { WebView mWebView; int Result; @Override public void onCreate (Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.visor); Bundle extras=getIntent().getExtras(); String s= extras.getString("url"); mWebView = (WebView) findViewById(R.id.webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setPluginsEnabled(true); mWebView.getSettings().setAllowFileAccess(true); mWebView.loadUrl(s); mWebView.setWebViewClient(new VisorClient()); mWebView.getSettings().setBuiltInZoomControls(true); } private class VisorClient extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { lanzarIntro(); } @Override public void onPageFinished(WebView view, String url) { mWebView.loadUrl(url); } } public void lanzarIntro(){ Intent i=new Intent (this, Intro.class); startActivity(i); } } 

Solutions Collecting From Web of "在Android应用程序的webview中加载URL时启动屏幕"

我这样做是通过最初显示一个ImageView,然后一旦加载了WebView,就像这样交换它们的可见性

  WebView wv = (WebView) findViewById(R.id.webView1); wv.getSettings().setJavaScriptEnabled(true); wv.setWebViewClient(new WebViewClient() { ... @Override public void onPageFinished(WebView view, String url) { //hide loading image findViewById(R.id.imageLoading1).setVisibility(View.GONE); //show webview findViewById(R.id.webView1).setVisibility(View.VISIBLE); } }); wv.loadUrl("http://yoururlhere.com"); 

我的xml布局看起来像这样

    

我有一项活动。 1个xml文件和1个java类。 在xml文件里面我有:

  1. 的WebView
  2. ImageView,我的应用程序的标志,
  3. ProgressBar和
  4. TextView,应用版本。

main.xml代码:

 < ?xml version="1.0" encoding="utf-8"?>       

NovcanikActivity.java代码:

 package zm.Nocanik; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.webkit.DownloadListener; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; public class NovcanikActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); WebView webview = (WebView) findViewById(R.id.webView1); WebSettings websettings = webview.getSettings(); websettings.setJavaScriptEnabled(true); websettings.setSaveFormData(false); websettings.setSavePassword(false); webview.loadUrl("http://m.novcanik.net/?appvers=1.0"); webview.setHorizontalScrollBarEnabled(false); webview.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); webview.setBackgroundColor(128); webview.setWebViewClient(new NovcanikWebViewClient()); webview.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); startActivity(intent); } }); } public void visible(){ WebView webview = (WebView) findViewById(R.id.webView1); ImageView logo = (ImageView) findViewById(R.id.imageView1); ProgressBar bar = (ProgressBar) findViewById(R.id.progressBar1); TextView version = (TextView) findViewById(R.id.textView1); webview.setVisibility(10); logo.setVisibility(0); bar.setVisibility(0); version.setVisibility(0); } public void unvisible(){ WebView webview = (WebView) findViewById(R.id.webView1); ImageView logo = (ImageView) findViewById(R.id.imageView1); ProgressBar bar = (ProgressBar) findViewById(R.id.progressBar1); TextView version = (TextView) findViewById(R.id.textView1); webview.setVisibility(0); logo.setVisibility(10); bar.setVisibility(10); version.setVisibility(10); } private class NovcanikWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView webview, String url){ webview.loadUrl(url); return true; } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { // TODO Auto-generated method stub view.loadUrl("file:///android_asset/noconnection.html"); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { visible(); } @Override public void onPageFinished(WebView view, String url) { unvisible(); } } } 

对不起,没有说明。 如果需要描述,我将详细描述整个代码。