我有一个带有加载 url 的 WeView 的 Activity,我想在网站加载期间显示一个小等待对话框,所以我尝试了这个:
private ProgressDialog dialog = new ProgressDialog(MyNameActivity.this);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
setContentView(R.layout.web_view_activity);
WebView wv;
wv = (WebView) findViewById(R.id.areaWebSolver);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
if (dialog.isShowing()) {
dialog.dismiss();
}
}
});
dialog.setMessage("Loading..Please wait.");
dialog.setCanceledOnTouchOutside(false);
dialog.show();
wv.loadUrl(url);
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
}
不幸的是,它不起作用,并且应用程序崩溃并source not found
...如果我尝试删除进度对话框代码,则活动可以正常工作。怎么了?我该如何解决这个问题?