如果我在 shouldOverrideUrlLoading 上返回true,则在加载新网址时,网页视图无法处理 onPageFinish 。
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.abc.com")) {
Intent intent = new Intent(context, MyActivity.class);
context.startActivity(intent);
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
在页面完成时停止进度。
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progress.setVisibility(View.GONE);
}
答案 0 :(得分:0)
try this code
webview.setWebViewClient(new myWebClient());
webview.setWebChromeClient(new WebChromeClient()
{
public void onProgressChanged(WebView view, int progressInt)
{
if (progressInt < 80 && progress.getVisibility() == ProgressBar.GONE)
{
progress.setVisibility(ProgressBar.VISIBLE);
}
if (progressInt >= 80)
{
progress.setVisibility(ProgressBar.GONE);
}
}
});
public class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
progress.setVisibility(View.VISIBLE);
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
progress.setVisibility(View.GONE);
}
}