android自定义404页面,如何给webview页面自定义404页面
//示例地图类packagecom.can2do.doimobile.news;importandroid.os.Bundle;importandroid.os.Handler;importandroid.os.Message;importandroid.webkit.WebView;importandroid.webkit.WebViewClient;importandroid.widget.T
//示例地图类
packagecom.can2do.doimobile.news;importandroid.os.Bundle;importandroid.os.Handler;importandroid.os.Message;importandroid.webkit.WebView;importandroid.webkit.WebViewClient;importandroid.widget.TextView;importcom.can2do.doimobile.R;importcom.can2do.doimobile.base.BaseUiWeb;importcom.can2do.doimobile.base.C;public class UiNewsOne extendsBaseUiWeb {private String tag = null;privateWebView mWebViewMap;
@Overridepublic voidonStart() {super.onStart();
setContentView(R.layout.ui_news_one);
Bundle params= this.getIntent().getExtras();
tag= params.getString("tag");
TextView titleText= (TextView) this.findViewById(R.id.main_top_title1);
titleText.setText(tag);
mWebViewMap=(WebView) findViewById(R.id.web_news_one);
mWebViewMap.getSettings().setJavaScriptEnabled(true);
mWebViewMap.setWebViewClient(newWebViewClient(){
});
mWebViewMap.setWebViewClient(newWebViewClient() {public void onReceivedError(WebView view, interrorCode, String description, String failingUrl)
{
view.stopLoading();
view.clearView();
Message msg=handler.obtainMessage();//发送通知,加入线程
msg.what=1;//通知加载自定义404页面
handler.sendMessage(msg);//通知发送!
}public booleanshouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);return true;
}
});
mWebViewMap.loadUrl(C.news.news1);this.setWebView(mWebViewMap);this.startWebView();
}protected Handler handler = newHandler(){public voidhandleMessage(Message message){switch(message.what) {case 1:
mWebViewMap.loadUrl("file:///android_asset/www/404/404.html");break;
}
}
};
}
更多推荐
所有评论(0)