我尝试在 onPageStarted 期间创建一个进度对话框,并在 onpageFinished 时关闭,但加载页面后进度对话框仍在 Web 视图中
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.webviewactivity);
WebView webview=(WebView)findViewById(R.id.webViewActivityWebView);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebChromeClient(new WebChromeClient()
{
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
value=newProgress;
activity.setTitle("Loading..");
activity.setProgress(newProgress*100);
if(newProgress==100)
{
activity.setTitle(R.string.app_name);
}
}
});
webview.setWebViewClient(new WebViewClient(){
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
activity.setTitle("Error On Page");
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
loadDialog();
}
public void onPageFinished(WebView view, String url) {
progressDialog.dismiss();
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webview.loadUrl("http://www.google.com");
}
public void loadDialog()
{
progressDialog=ProgressDialog.show(this, "Loading", "Please Wait", true, true);
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.webviewactivity);
WebView webview=(WebView)findViewById(R.id.webViewActivityWebView);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebChromeClient(new WebChromeClient()
{
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
value=newProgress;
activity.setTitle("Loading..");
activity.setProgress(newProgress*100);
if(newProgress==100)
{
activity.setTitle(R.string.app_name);
}
}
});
webview.setWebViewClient(new WebViewClient(){
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
activity.setTitle("Error On Page");
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
loadDialog();
}
public void onPageFinished(WebView view, String url) {
progressDialog.dismiss();
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webview.loadUrl("http://www.google.com");
}
public void loadDialog()
{
progressDialog=ProgressDialog.show(this, "Loading", "Please Wait", true, true);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论