WebView图片点击查看

需求:WebView中的图片点击后放大全屏查看

this.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                LogHelp.d("lyg", "shouldOverrideUrlLoading:" + url);
                if (!TextUtils.isEmpty(url) && isAutoUrl() && (url.startsWith("http://") || url
                        .startsWith("xuehu://"))) {
                    URLBus.doURL(url, "", getContext(), CustomWebView.this, isOpenNewActivity);
                    return true;
                } else {
                    return super.shouldOverrideUrlLoading(view, url);
                }
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                EventBus.getDefault().post(new WebViewCloseEvent());
                mLists.clear();
                addImageListener();
            }

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                super.onReceivedSslError(view, handler, error);
                handler.proceed();
            }
        });
//---------webview图片点击开始------------------
    private void addImageListener() {
        //in some case, src of an img tag might be base64 string but no an url
        //we can get image url by data-src if exists
        loadUrl("javascript:(function(){ "
                + " var objs = document.getElementsByTagName(\"img\"); "
                + " for(var i=0;i<objs.length;i++)  "
                + " {"
                + "     if(objs[i].getAttributeNode(\"onclick\").specified) continue; "
                + "     window.imageListener.addImage(objs[i].src, objs[i].dataset.src); "
                + "     objs[i].οnclick=function()  "
                + "    {  "
                + "      window.imageListener.openImage(this.src, this.dataset.src);  "
                + "     }  "
                + " } "
                + " })()");
    }

通过重写js来实现

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值