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.html3.Android中使用WebView, WebChromeClient和WebViewClient加载网页http://www.apkbus.com/android-20053-1-1.html4.Android WebView开发常见问题http://www.apkbus.com/android-13095-1-1.html5.Android开发过程中有关WebView开发问题集锦http://www.apkbus.com/android-16190-1-1.html6.android webView 使用方法http://www.apkbus.com/android-20436-1-1.html7.Android官方文档在WebView中构建Web Appshttp://www.apkbus.com/android-20751-1-1.html8.Webview开发常用知识点http://www.apkbus.com/android-43956-1-1.html9.Android 控件之WebViewhttp://www.apkbus.com/android-1352-1-1.html10.WebView使用中遇到的一些问题&解决http://www.apkbus.com/android-14541-1-1.html11.Android 浅谈webview中的Javascripthttp://www.apkbus.com/android-6209-1-1.html12.android开发之WebView使用Javascript详解http://www.apkbus.com/android-16191-1-1.html13.第二十九讲:WebView学习指南http://www.apkbus.com/android-1114-1-1.html14.Webview在实际开发中比较实用资料http://www.apkbus.com/android-51717-1-1.html




二、WebView简单应用
1.网络视图 WebViewhttp://www.apkbus.com/android-985-1-1.html2.Android WebView删除缓存http://www.apkbus.com/android-21006-1-1.html3.WebView使用http://www.apkbus.com/android-4872-1-1.html4.WebView的使用心得与范例http://www.apkbus.com/android-18646-1-1.html5.WebView使用总结(应用函数与JS函数互相调用)http://www.apkbus.com/android-17219-1-1.html6.Android学习之利用WebView打开网页http://www.apkbus.com/android-20188-1-1.html7.Android webview下载歌曲(一)http://www.apkbus.com/android-2976-1-1.html




三、WebView实例源码
1.android WebView设置setInitialScale(...)后,修改设置的值,问题解决http://www.apkbus.com/android-45063-1-1.html2.Android中WebView和JavaScript进行简单通信http://www.apkbus.com/android-18803-1-1.html3..webview 实现翻页功能http://www.apkbus.com/android-51714-1-1.html

四、高级

缓存处理

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



更多相关文章

  1. android webview 设置“ 正在加载,请稍候”
  2. 加载时不直接弹出输入法
  3. 在Android(OPhone)模拟器中加载和使用SDCard卡
  4. android 加载图片轻松避免OOM(out of memory) 支持设置缓存大小,
  5. 画廊视图Gallery
  6. 阅读《Android 从入门到精通》(21)——滚动视图
  7. WebView android sdk 25加载“file:///..."失败解决
  8. android 实现视频缓存
  9. Android sqlite约束-视图-检查

随机推荐

  1. Android(安卓)SDK 在线更新镜像服务器资
  2. Android(安卓)7.0 之后抓包 Charles 手机
  3. Android横竖屏总结全
  4. MAC系统Android Studio默认debug签名证书
  5. Android StrictMode 详解
  6. System.EntryPointNotFoundException: Un
  7. Android使用Cordova框架开发Android Hybr
  8. Android(安卓)-- 点击双下返回退出程序
  9. android资源引用
  10. 【Android UI】ListView系列一(基础篇)