Android WebView 图片宽度自适应屏幕
实现方法如下
WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true);//支持JS String js = "<script type=\"text/javascript\">"+ "var imgs = document.getElementsByTagName('img');" + // 找到img标签 "for(var i = 0; i<imgs.length; i++){" + // 逐个改变 "imgs[i].style.width = '100%';" + // 宽度改为100% "imgs[i].style.height = 'auto';" + "}" + "</script>"; mWebView.loadData(html+js,"text/html; charset=UTF-8", null);
注:js一定要跟在html内容后