您的位置:首页 > 移动开发

Android WebView相关知识(全)

2015-05-15 15:15 239 查看
WebView教程

基本使用

webview=(WebView)findViewById(R.id.webview);
//设置WebView属性,能够执行JavaScript脚本
webview.getSettings().setJavaScriptEnabled(true);
//加载URL内容
webview.loadUrl("http://www.baidu.com");
//设置web视图客户端
webview.setWebViewClient(new MyWebViewClient());
webview.loadUrl("file:///android_asset/guide.html");//加载assets资源文件里的html
//web视图客户端
public class MyWebViewClient extends WebViewClient{
public boolean shouldOverviewUrlLoading(WebView view,String url){
view.loadUrl(url);
return true;
}


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>

清楚缓存

// clear the cache before time numDays
private int clearCacheFolder(File dir, long numDays) {
int deletedFiles = 0;
if (dir!= null && dir.isDirectory()) {
try {
for (File child:dir.listFiles()) {
if (child.isDirectory()) {
deletedFiles += clearCacheFolder(child, numDays);
}
if (child.lastModified() < numDays) {
if (child.delete()) {
deletedFiles++;
}
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
return deletedFiles;
}

//优先使用缓存:
WebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

//不使用缓存:
WebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
//在退出应用的时候加上如下代码
File file = CacheManager.getCacheFileBaseDir();
if (file != null && file.exists() && file.isDirectory()) {
for (File item : file.listFiles()) {
item.delete();
}
file.delete();
}

context.deleteDatabase("webview.db");
context.deleteDatabase("webviewCache.db");


显示webView加载进度

<span style="font-size:14px;"> webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
//Activity和Webview根据加载程度决定进度条的进度大小
//当加载到100%的时候 进度条自动消失
context.setProgress(progress * 100);
}
});  </span>


2.webview学习记录 http://www.apkbus.com/android-44567-1-1.html 3.Android中使用WebView, WebChromeClient和WebViewClient加载网页 http://www.apkbus.com/android-20053-1-1.html 4.Android WebView开发常见问题 http://www.apkbus.com/android-13095-1-1.html 5.Android开发过程中有关WebView开发问题集锦 http://www.apkbus.com/android-16190-1-1.html 6.android webView 使用方法 http://www.apkbus.com/android-20436-1-1.html 7.Android官方文档在WebView中构建Web Apps http://www.apkbus.com/android-20751-1-1.html 8.Webview开发常用知识点 http://www.apkbus.com/android-43956-1-1.html 9.Android 控件之WebView http://www.apkbus.com/android-1352-1-1.html 10.WebView使用中遇到的一些问题&解决 http://www.apkbus.com/android-14541-1-1.html 11.Android 浅谈webview中的Javascript http://www.apkbus.com/android-6209-1-1.html 12.android开发之WebView使用Javascript详解 http://www.apkbus.com/android-16191-1-1.html 13.第二十九讲:WebView学习指南 http://www.apkbus.com/android-1114-1-1.html 14.Webview在实际开发中比较实用资料 http://www.apkbus.com/android-51717-1-1.html[/code] 
二、WebView简单应用

1.网络视图 WebView http://www.apkbus.com/android-985-1-1.html 2.Android WebView删除缓存 http://www.apkbus.com/android-21006-1-1.html 3.WebView使用 http://www.apkbus.com/android-4872-1-1.html 4.WebView的使用心得与范例 http://www.apkbus.com/android-18646-1-1.html 5.WebView使用总结(应用函数与JS函数互相调用) http://www.apkbus.com/android-17219-1-1.html 6.Android学习之利用WebView打开网页 http://www.apkbus.com/android-20188-1-1.html 7.Android webview下载歌曲(一) http://www.apkbus.com/android-2976-1-1.html[/code] 
三、WebView实例源码

1.android WebView设置setInitialScale(...)后,修改设置的值,问题解决 http://www.apkbus.com/android-45063-1-1.html 2.Android中WebView和JavaScript进行简单通信 http://www.apkbus.com/android-18803-1-1.html 3..webview 实现翻页功能 http://www.apkbus.com/android-51714-1-1.html[/code] 四、高级

缓存处理

http://www.open-open.com/lib/view/open1392188052301.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: