单击 Web 视图中的任何链接时如何显示进度对话框
我有一个标题,其中有一些按钮,下面有一个网络视图。我有一个工作进度对话框,用于显示页面最初打开的时间和单击按钮的时间。问题是当我单击网络视图内的任何链接时,不会显示进度对话框。有谁知道实现这一目标的最佳方法?我在下面包含了我的 WebViewClient 和其中一个按钮的代码。
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
ProgressDialog dialog = ProgressDialog.show(myActivity.this, "","Loading...", true);
public void onPageFinished(WebView view, String url) {
dialog.dismiss();
}
});
final Button btnCategory = (Button) findViewById(R.id.btnCategory);
btnCategory.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient(){
ProgressDialog dialog = ProgressDialog.show(myActivity.this, "","Loading...", true);
public void onPageFinished(WebView view, String url) {
dialog.dismiss();
}
});
mWebView.loadUrl("http://mywebsite.com/page");
}
});
I have a header with some buttons in it and a webview below it. I have a working progress dialog for when the page originally opens and when a button is clicked. The problem is when I click any links inside of the webview a progress dialog doesn't show. Does anyone know the best method to make this happen? I included below the code for my WebViewClient and one of the buttons.
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
ProgressDialog dialog = ProgressDialog.show(myActivity.this, "","Loading...", true);
public void onPageFinished(WebView view, String url) {
dialog.dismiss();
}
});
final Button btnCategory = (Button) findViewById(R.id.btnCategory);
btnCategory.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient(){
ProgressDialog dialog = ProgressDialog.show(myActivity.this, "","Loading...", true);
public void onPageFinished(WebView view, String url) {
dialog.dismiss();
}
});
mWebView.loadUrl("http://mywebsite.com/page");
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无需尝试显示对话框,只需切换进度条的可见性即可。
我自己没有尝试过,但它可能看起来像这样:
Instead of trying to show a dialog you could just toggle the visibility of a progress bar.
I haven't tried it myself but it could look like this:
您可以使用相对布局来包含网络视图和进度条(位于相对布局的中心)。
you could use a relativelayout to include the webview and the progressbar (which is centered in the relativelayout).