最近一直在写webView的东西,发现有好多功能点,记一下。

JS调用Android的方法:

在JS中:写 window.JavaScriptinterface.closecurrent();   
在Adnriod中:    webView.addJavascriptInterface(new backJS(), "JavaScriptinterface");
注意:new backJS()名字可以随意取,“JavaScriptinterface”对应JS
    class backJS {        //没有返回参数        @JavascriptInterface        public void closeCurrentWin() {            //内容为要调用的方法        }        //返回一个String类型参数        @JavascriptInterface        public void closeCurrentWin(String flash) {            //内容为要调用的方法        }           }

webView下拉刷新(SwipeRefreshLayout)

使用android.support.v4.widget.SwipeRefreshLayout进行下拉刷新,如果使用过程中找不到包报错,替换一下support.v4就好了,也可以点击链接下载直接替换

http://download.csdn.net/detail/sunflower_12/9806495

1、xml

 .support.v4.widget.SwipeRefreshLayout        android:id="@+id/swipe_container_links"        android:layout_width="match_parent"        android:layout_height="match_parent" >        "@+id/webView_link"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:scrollbars="none" />    .support.v4.widget.SwipeRefreshLayout>

2、初始化 (设置监听和进度条颜色)

swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container_links);        swipeLayout.setOnRefreshListener(this);        swipeLayout.setColorScheme(R.color.greys_1, R.color.greys_2,                R.color.greys_3, R.color.greys_4);

3、刷新

    @Override    public void onRefresh() {        // 重新刷新页面        webView_link.loadUrl(webView_link.getUrl());    }

下载文件

1、设置监听
webView.setDownloadListener(new MyWebViewDownLoadListener());
2、下载到sd卡的指定目录
    private class MyWebViewDownLoadListener implements DownloadListener {        @Override        public void onDownloadStart(String url, String userAgent,                String contentDisposition, String mimetype,                long contentLength) {            if (!Environment.getExternalStorageState().equals(                    Environment.MEDIA_MOUNTED)) {                Toast t = Toast.makeText(LinkActivity.this, "需要SD卡。",                        Toast.LENGTH_LONG);                t.setGravity(Gravity.CENTER, 0, 0);                t.show();                return;            }            loadFiles(upUrl);//根据URl下载即可        }    }

注意:在使用webView上传图片时,正常是单张上传,若想同时上传多个图片,要自定义,同时JS中写个按钮,

更多相关文章

  1. Android中Activity状态的保存和恢复:onSaveInstanceState和onRest
  2. android 连接服务器的方法及安全性问题
  3. android中Bitmap的放大和缩小的方法
  4. android中LayoutParams设置参数的理解
  5. Android遍历文件Listfile返回值为null问题解决方法适用Android8.
  6. Android上传文件至PHP服务器
  7. Android 最新获取手机内置存储大小,SD卡存储空间大小方法
  8. Android客户端上传文件到服务器端
  9. Android 启动浏览器的方法

随机推荐

  1. Visual Studio 2015正式发布
  2. Android实现Rxjava2+Retrofit完美封装
  3. Android学习手记(2) Activity生命周期
  4. 【Android】 onClick与onTouch并存触发的
  5. Project interpreter not specified(ecli
  6. android和ios GoogleMap画导航线路图 路
  7. Android(安卓)创世纪 第一天
  8. 用x86的模拟器内核记得安装intel的haxm
  9. android 获取手机内存大小
  10. android 之 Androidpn 消息推送总结