gpt4 book ai didi

android - json 值的 img src 属性在 android TextView 中显示蓝色小框

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:03:36 25 4
gpt4 key购买 nike

我已经检索到 JSON 值以在 android TextView 中显示它这是我的示例 JSON 值

    "introtext": "The District Administration Office has sealed the case was underway.<img src="images/dec_09_Lazimpat_road_b.JPG" alt="" />"

我用了 Apache Common lang Liabrary像这样转义 HTML 属性和样式。

String str = org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4(stringValue);

并且我已经像这样将值设置为 TextView

textView.setText(Html.fromHtml(str));

到这里为止一切正常,但是 TextView 中的 text 显示如下图

enter image description here

这个小蓝框显示在 img src 属性所在的位置。我浪费了太长时间试图删除它。请帮助我如何从 TextView 中删除此框。任何帮助将不胜感激。

最佳答案

试试这段代码:

String s = "The District Administration Office has sealed the case was underway.<img src="images/dec_09_Lazimpat_road_b.JPG" alt="" />";
String str = Html.fromHtml(s).toString();
///// Remove all img tags using Regular Expression
str = str.replaceAll("[<](/)?img[^>]*[>]", "");
textView.setText(Html.fromHtml(str));

关于android - json 值的 img src 属性在 android TextView 中显示蓝色小框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34327235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com