下面是我的 WebViewClient 代码。我通过单击按钮调用了该类。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if (progress == 100)
activity.setTitle(R.string.app_name);
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// Handle the error
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.loadUrl("http://mylink.com");
// String customHtml =
// "<html><body><h1>Hello, WebView</h1></body></html>";
// webView.loadData(customHtml, "text/html", "UTF-8");
}
}
加载 WebViewClient 需要更多时间。我需要加快速度。有什么建议
最佳答案
据我所知,您的代码没有任何问题。我强烈建议您检查您所连接的 Web 服务器的性能,因为这很可能是您出现问题的原因。特别是查看服务器响应时间。要测试 Web View 的性能,请尝试将 URL 设置为快速响应的网站,例如 google.com。
关于android - 首次调用 WebViewClient 时页面加载缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10579176/