首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可以通过Html.fromHtml()在Android TextView的HTML标签中显示来自url的图片吗?

可以通过Html.fromHtml()在Android TextView的HTML标签中显示来自url的图片吗?
EN

Stack Overflow用户
提问于 2017-02-23 13:47:16
回答 1查看 728关注 0票数 0

这是代码,我想要显示图像。我还尝试了它的大小。

代码语言:javascript
复制
TextView textViewHtml = (TextView) findViewById(R.id.text_html_program);
        Spanned spanned = Html.fromHtml( "<b>text_html_program: Constructed from HTML programmatically.</b>"
                + "  Text with a <a href=\"http://www.google.com\">link</a> "
                +"<b><img src=\"http://innovativeprofessionaloffices.com/wp-content/uploads/2014/07/seo-for-small-business.jpg\" alt=\"testing\"></b>"
                + "created in the Java source code using HTML.");
        textViewHtml.setText(spanned);
        textViewHtml.setMovementMethod(LinkMovementMethod.getInstance());
EN

回答 1

Stack Overflow用户

发布于 2017-02-23 13:54:55

您可以使用以下模式获取img标签:

代码语言:javascript
复制
    String ptr= "src\\s*=\\s*([\"'])?([^\"']*)";
        Pattern p = Pattern.compile(ptr);
        Matcher m;
//find the img tag

  m = p.matcher(html_string_containg_img_Tag);
        if (m.find()) {
           m.group(2),img);//this line get the image tag from give string
        }

希望这对你有帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42408022

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档