【问题标题】:Is it possible to Display a image from url in HTML tag in Android TextView through Html.fromHtml()是否可以通过 Html.fromHtml() 在 Android TextView 的 HTML 标记中显示来自 url 的图像
【发布时间】:2017-02-23 13:54:54
【问题描述】:

这里是代码, 我希望显示图像。我也尝试了 Size。

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());

【问题讨论】:

标签: android html image textview


【解决方案1】:

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

    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
        }

希望对你有帮助

【讨论】:

  • 我不认为这是显示图像的解决方案,兄弟我想在文本视图中显示图像,这是我的问题。
  • 你不能在 textView 中显示图像,你必须使用 ImageView 。
  • 可以设置,但它会帮助你从字符串中获取 img url。而不是用 url 做任何你想做的事情。
猜你喜欢
  • 2011-02-21
  • 1970-01-01
  • 1970-01-01
  • 2013-04-16
  • 1970-01-01
  • 1970-01-01
  • 2013-04-30
  • 1970-01-01
  • 2014-05-21
相关资源
最近更新 更多