没设置之前
设置之后
添加配置
image.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
网友评论