第一步:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
在onCreate里面新增以下code
@Overridepublic void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); web_view.loadUrl("file:///android_asset/error.html");}
第二步:
建立一个error.xml
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Error</title></head><body style=" background:#CCC"> <div style="margin:0 auto;"> <span> <h1 align="center" id="title" style="font-family:微软正黑体;">欧欧,出错了……</h1> </span> <span> <h3 align="center"><a href="http://192.168.1.82/amily/">回首页</a></h3> </span> </div></body></html>
第三步:
建立assets资料夹并将error.html放入assets资料夹中
方法:app>src>main>右键New>Folder>Asset Folder