我正在开发在webview中加载url的应用程序。
代码是:
web = (WebView) findViewById(R.id.myWeb);
web.resumeTimers();
final WebSettings settings = web.getSettings();
settings.setJavaScriptEnabled(true);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setPluginState(android.webkit.WebSettings.PluginState.ON_DEMAND);
web.setWebViewClient(new myWebClient());
web.loadUrl(url);
班级代码
public class myWebClient extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@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
view.loadUrl(url);
return true;
}
}
我已经添加了INTERNET权限并完成了android:hardwareAccelerated =" true"但它仍然给出错误:android 4.2.2上没有网页。我也检查了互联网连接。
在其他版本如4.4.2和4.0.4网页上正在加载。
答案 0 :(得分:0)
实现webView.setWebViewClient,如下所示:
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error){
handler.proceed();
}
});
}
它对我有用。