zoukankan      html  css  js  c++  java
  • 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].onclick=function()  "
                    + "    {  "
                    + "      window.imageListener.openImage(this.src, this.dataset.src);  "
                    + "     }  "
                    + " } "
                    + " })()");
        }

    通过重写js来实现

  • 相关阅读:
    elf和内存分布
    平衡二叉树
    sdio驱动
    wifi
    阻塞赋值与非阻塞赋值
    线性失真与非线性失真
    数字前端,后端介绍
    总线
    并行全比较排序算法&并对角标排序
    verilog memory
  • 原文地址:https://www.cnblogs.com/anni-qianqian/p/8333985.html
Copyright © 2011-2022 走看看