Java 如何在从web视图加载内容时添加ProgressDialog
这是我将网页加载到web视图的程序。我的问题是如何在从web视图加载内容时添加ProgressDialogJava 如何在从web视图加载内容时添加ProgressDialog,java,webview,Java,Webview,这是我将网页加载到web视图的程序。我的问题是如何在从web视图加载内容时添加ProgressDialog public class Openpage extends Activity { WebView wb=null; String s1=null; @SuppressLint({ "SetJavaScriptEnabled", "HandlerLeak" }) public void onCreate(Bundle savedInstanceState) { super
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();
}
}
public类Openpage扩展活动{
WebView wb=null;
字符串s1=null;
@SuppressLint({“SetJavaScriptEnabled”,“HandlerLeak”})
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.newsfeed);
Intent i=getIntent();
s1=i.getStringExtra(“链接”);
Toast.makeText(this,s1,Toast.LENGTH_LONG).show();
日志d(s1,“hai”);
ProgressDialog进度=新建ProgressDialog(此);
progress.setMessage(“加载…”);
新建MyTask(progress.execute();
}
公共类MyTask扩展了AsyncTask{
私人进展对话进展;
公共MyTask(进度对话框进度){
这个。进步=进步;
}
公共无效onPreExecute(){
progress.show();
}
公共作废doInBackground(作废…作废){
wb=(WebView)findViewById(R.id.webView1);
wb.loadUrl(s1);
返回null;
}
PostExecute上的公共void(void void1){
进步。解散();
}
}
您可以了解页面的加载量
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if(progress == 100){
// Page has fully loaded. Cancel the progress dialog here
}
}
}))
你可以从报纸上读到