我有一个 WebView Activity ,有时由于 WIFI/DATA 连接断开或不良而无法正确加载。我想一旦部署了我的应用程序,这很可能在现实世界中发生。我的问题是如何用更漂亮的东西替换这个丑陋的错误?
另外,对于让我的 WebView Activity 不像浏览器,您还有其他技巧吗? 例如,在加载 WebView 时,我如何才能显示加载图标,而不是出现白屏?
非常感谢。
最佳答案
当找不到页面时,页面返回404错误,您需要做的就是处理它。
这可以通过设置 WebViewClient
并覆盖 onReceivedError
方法来完成。
你可以尝试这样的事情:
WebView wv = (WebView) findViewById(R.id.webView);
wv.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
//handle the 404
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
关于javascript - 用不那么难看的东西替换 WebView 中的 "Web page not available"错误? (安卓),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10746620/