webview 离线缓存,html5游戏适用

 1 public class MainActivity extends Activity {  2 
 3     private WebView mWebView;  4 
 5     private static final String URL = "http://nus40g1.chinaw3.com/demos/fruit-ninja/";  6 
 7  @Override  8     protected void onCreate(Bundle savedInstanceState) {  9         super.onCreate(savedInstanceState); 10  setContentView(R.layout.activity_main); 11         mWebView = (WebView) findViewById(R.id.webview); 12         WebSettings webSettings = mWebView.getSettings(); 13         webSettings.setJavaScriptEnabled(true); 14         webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//用缓存用缓存,没有用网络
15 
16         webSettings.setSupportZoom(true); 17         webSettings.setBuiltInZoomControls(true); 18         webSettings.setUseWideViewPort(true);//开启任意缩放比例 19 // webSettings.setAppCacheMaxSize(appCacheMaxSize) 可以设置缓存大小
20         mWebView.setInitialScale(10);//初始缩放数值
21  mWebView.loadUrl(URL); 22  } 23 
24 }

很简单就这样就可以了.主要是那个cache模式设置一下.这里我引用了一个html5的水果忍者的游戏,测试可用.平台android 4.0.

 

你可能感兴趣的:(webView)