WebView清除缓存的有效方法
2012-02-29 10:58
429 查看
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="webLoad" android:id="@+id/loadId" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="clearCache" android:id="@+id/clearId" /> <WebView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/webViewId" /> </LinearLayout>
public class WebCacheActivity extends Activity implements OnClickListener { private Button clearBtn, loadBtn; private WebView webView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); clearBtn = (Button) findViewById(R.id.clearId); loadBtn = (Button) findViewById(R.id.loadId); clearBtn.setOnClickListener(this); loadBtn.setOnClickListener(this); webView = (WebView) findViewById(R.id.webViewId); webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); webView.loadUrl("http://www.baidu.com/"); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.clearId://清除缓存的有效方法 webView.loadDataWithBaseURL(null, "","text/html", "utf-8",null); break; case R.id.loadId: webView.loadUrl("http://www.baidu.com/"); break; default: break; } } }
相关文章推荐
- iOS9 WKWebView清除缓存方法
- 关于安卓webview的loadUrl和reload方法缓存策略的区别发现记录
- iOS中清除缓存的方法 以及SDWebimage自带的清除缓存方法
- ios webview清除缓存Cookie
- webview 清除缓存
- webView清除缓存
- iOS WebView 清除缓存和Cookie
- android WebView清除缓存
- 清除eclipse中web项目缓存的方法
- SDWebImage手动清除缓存的方法
- ios清除缓存的两种有效方法
- ios webview清除缓存
- 关于离线缓存webView的新方法NSURLProtocol
- Android Webview清除缓存和Cookie
- android清除WebView使用的缓存的学习记录
- Android进阶篇-清除WebView的缓存
- webview清除缓存
- 清除WKWebView cookies的方法
- 安卓使用WebView清除缓存
- SDWebImage手动清除缓存的方法