---
title: "Android开发片段 WebView"
author: "04023129"
date: "2012-02-06T14:55:39Z"
tags: []
categories: ["移动开发"]
slug: "android-webview"
draft: false
lastmod: "2012-02-06T14:56:02Z"
id: 1395429
url: "https://zzh.iteye.com/blog/1395429"
---

```
 /** Called when the activity is first created. */
	WebView mWebView;
    @Override
    public void onCreate(Bundle icicle) { 
    	super.onCreate(icicle); 
    	setContentView(R.layout.main); 
    	mWebView = (WebView) findViewById(R.id.webView); 
    	mWebView.getSettings().setJavaScriptEnabled(true); 
    	mWebView.getSettings().setDatabaseEnabled(true);
    	mWebView.getSettings().setDomStorageEnabled(true);
    	mWebView.getSettings().setSaveFormData(true);
    	mWebView.setScrollBarStyle(0);
    	mWebView.getSettings().setBuiltInZoomControls(true);
    	mWebView.getSettings().setSupportZoom(true);
    	mWebView.getSettings().setDefaultZoom(ZoomDensity.CLOSE);
    	mWebView.loadUrl("http://10.X.X.X/app/excel/");
    	mWebView.setWebViewClient(new WebViewClient() {  
    	    @Override 
    	    public boolean shouldOverrideUrlLoading(WebView view, String url) {  
    	        view.loadUrl(url);  
    	        return true;  
    	    }  
    	});
    }
    public boolean onKeyDown(int keyCode, KeyEvent event) {  
        if (mWebView.canGoBack() && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {  
        	mWebView.goBack();  
            return true;  
        }  
        return super.onKeyDown(keyCode, event);  

    } 
```