android webview自定义,Android webview自定义错误页面

我正在创建使用WebView访问在线网站的应用程序.我被困在我必须添加代码以检查页面可用性的地方.

public class SpartanWeb extends Activity {

WebView mWebView;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

// Adds ProgRSS bar Support

this.getWindow().requestFeature(Window.FEATURE_PROGRESS);

setContentView(R.layout.main);

// Makes Progress bar Visible

getWindow().setFeatureInt(Window.FEATURE_PROGRESS,Window.PROGRESS_VISIBILITY_ON);

// Get Web view

mWebView = (WebView) findViewById(R.id.webView1);

WebSettings websettings = mWebView.getSettings();

websettings.setJavaScriptEnabled(true);

mWebView.stopLoading();

mWebView.clearCache(true);

mWebView.loadUrl("http://google.com");

mWebView.setHorizontalScrollBarEnabled(false);

mWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);

mWebView.setWebViewClient(new WebViewClient());

mWebView.setDownloadListener(new DownloadListener() {

public void onDownloadStart(String url,String userAgent,String contentDisposition,String mimetype,long contentLength) {

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setData(Uri.parse(url));

startActivity(intent);

}

});

// onProgressChanged

final Activity MyActivity = this;

mWebView.setWebChromeClient(new WebChromeClient() {

public void onProgressChanged(WebView view,int progress) {

// bar disappear after URL is loaded,and changes string to

// Loading...

MyActivity.setTitle("Loading...");

MyActivity.setProgress(progress * 100); // Make the bar

// disappear after URL

// is loaded

// Return the app name after finish loading

if (progress == 100)

MyActivity.setTitle(R.string.app_name);

}

});

}// EOM oc

public boolean onKeyDown(int keyCode,KeyEvent event) {

if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {

mWebView.goBack();

return true;

}

return super.onKeyDown(keyCode,event);

}

}

我试图添加onReceivedError但由于某种原因自定义页面没有加载.

/** Called when the activity is first created. */

public void onReceivedError(WebView view,int errorCode,String description,String failingUrl)

{

mWebView.loadUrl("file:///android_asset/error.html");

}

请告知该怎么做.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值