这是我将网页加载到网页视图的程序。我的问题是如何在从Web视图加载内容时添加ProgressDialog。
public class Openpage extends Activity {
WebView wb=null;
String s1=null;
@SuppressLint({ "SetJavaScriptEnabled", "HandlerLeak" })
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newsfeed);
Intent i=getIntent();
s1=i.getStringExtra("link");
Toast.makeText(this, s1, Toast.LENGTH_LONG).show();
Log.d(s1, "hai");
ProgressDialog progress = new ProgressDialog(this);
progress.setMessage("Loading...");
new MyTask(progress).execute();
}
public class MyTask extends AsyncTask<Void, Void, Void> {
private ProgressDialog progress;
public MyTask(ProgressDialog progress) {
this.progress = progress;
}
public void onPreExecute() {
progress.show();
}
public Void doInBackground(Void...voids) {
wb=(WebView)findViewById(R.id.webView1);
wb.loadUrl(s1);
return null;
}
public void onPostExecute(Void void1) {
progress.dismiss();
}
}
答案 0 :(得分:0)
您可以从
了解页面的加载量webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if(progress == 100){
// Page has fully loaded. Cancel the progress dialog here
}
}
});
您可以从here
阅读