search

Home  >  Q&A  >  body text

Android Webview可以实现点击加载图片吗?

为了节省手机流量,想在加载网页图片之前先全部加载一个本地的图片提示用户点击加载图片;有办法在Webview中实现吗?

PHP中文网PHP中文网2772 days ago600

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 17:12:23

    Of course, it can be achieved through the interaction between Java and js. So you need to know the relevant knowledge of js.

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:12:23

    You can refer to this https://github.com/pedant/safe-java-js-webview-bridge

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:12:23

    This problem can be realized with WEB technology.

    First there is a picture tag

    <img src="placehoder.jpg" src="realSrc.jpg">

    placehoder.jpg is your local placeholder image, and src="realSrc.jpg" saves the real URL of the image tag. placehoder.jpg 是你的本地占位图,src="realSrc.jpg" 保存的是该图片标签真实 URL。

    最后就加个点击事件替换 src

    Finally, add a click event to replace src🎜
    document.addEventListener('touchstart', function(e){
        var target = e.target;
        if(target.tagName === 'IMG' && target.src !== target.dataset.src) {
            target.src = target.dataset.src;
        }
    
    })

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:12:23

    http://bbs.deviceone.net/forum.php?mod=viewthread&tid=123&extra=page%3D1
    Is this the effect?

    reply
    0
  • Cancelreply