我试图在我的 web 视图上显示一个警告框而不是“网页不可用”错误页面,但即使在根据文档添加 onReceivedError() 方法后也无法正常工作,如果我遗漏了什么,请建议我,这是我的代码...
public class CloudPageHolder extends Activity {
WebView mWebView;
ProgressDialog _dialog ;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.loadUrl("file:///android_asset/www/MyPage.html");
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
mWebView.getSettings().setPluginsEnabled(false);
mWebView.getSettings().setSupportMultipleWindows(false);
mWebView.getSettings().setSavePassword(false);
mWebView.getSettings().getAllowFileAccess();
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
new AlertDialog.Builder(CloudPageHolder.this)
.setMessage("Something went wrong!")
.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
})
.setCancelable(false)
.create()
.show();
}
});
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, final String message, final android.webkit.JsResult result)
{
new AlertDialog.Builder(CloudPageHolder.this)
.setMessage(message)
.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
result.confirm();
}
})
.setCancelable(false)
.create()
.show();
return true;
}
});
}
提前致谢...