没设置之前
![](https://img.haomeiwen.com/i1722765/aec4bab34538bc90.png)
设置之后
![](https://img.haomeiwen.com/i1722765/654afa24f8f8fafb.png)
添加配置
![](https://img.haomeiwen.com/i1722765/e2793d5e732504be.png)
![](https://img.haomeiwen.com/i1722765/529cb0ab177cff6d.png)
implementation 'org.jsoup:jsoup:1.12.1'
/**
* WebView加载网页图片显示太大的解决方案 图片尺寸超过屏幕宽度,最大显示屏幕的宽度,否则展示原图的大小 https://blog.csdn.net/qq_35008536/article/details/52281161
* @param htmltext
* @return
*/
fun getNewContent(htmltext: String?): String? {
val doc: Document = Jsoup.parse(htmltext)
val elements: Elements = doc.getElementsByTag("img")
for (element in elements) {
element.attr("width", "100%").attr("max-width", "100%").attr("height", "auto")
}
return doc.toString()
}
lockWebView.loadDataWithBaseURL(null,getNewContent(htmlText),"text/html","UTF-8",null)
jar包下载地址
https://jsoup.org/download
网友评论