gpt4 book ai didi

android - 如何从 webview 中隐藏 "Web page not available"页面/错误?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:43:43 24 4
gpt4 key购买 nike

我想隐藏那个错误,只显示一个空白页面和一个对话框。

如何隐藏它?

最佳答案

不是那么明显。因为 WebViewClient 无论如何都会打开标准错误页面,即使您覆盖了 onReceivedError 方法。所以我们需要在处理错误事件后打开自定义错误页面。

因此,您应该覆盖 onReceivedError in WebViewClient ,然后如果您处理所需的错误代码(请参阅 WebViewClient 中的 ERROR_ 常量),您应该打开空白页面或另一个页面以隐藏标准 Android“网页不可用”页面。

像这样:

@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
if (errorCode == neededErrorCode) {
hideErrorPage(view);
}
}

private void hideErrorPage(WebView view) {
// Here we configurating our custom error page
// It will be blank
String customErrorPageHtml = "<html></html>";
view.loadData(customErrorPageHtml, "text/html", null);
}

关于android - 如何从 webview 中隐藏 "Web page not available"页面/错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12902989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com