简体   繁体   English

如何在Android TextView里面显示HTML img标签

[英]How to display HTML img tag inside Android TextView

Hi I am new to android development.嗨,我是android开发的新手。 I have a string which looks like this我有一个看起来像这样的string

String source = "Hi <b>Ram</b>. This is the Formula <img src=\"https://i.postimg.cc/wTXjVKDf/ste.png\"/> Check it Out";

I want to display it in TextView .我想在TextView中显示它。 I used我用了

 textView.setText(Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY));

to achieve this.为达到这个。
But it Looks like this但它看起来像这样在此处输入图像描述

Instead of Image , there is a color box showing .而不是Image ,有一个color box showing I saw several questions in Stack Overflow.我在 Stack Overflow 中看到了几个问题。 But all answers are outdated.但所有答案都已过时。 Now those answers are not working.现在这些答案不起作用。 Please help me to solve this problem.请帮我解决这个问题。

You should use WebView instead of TextView您应该使用WebView而不是TextView

   WebView = findViewById(R.id.WebView);
   WebView.loadData(source, "text/html", "utf-8");

You will get the same output.您将获得相同的 output。

The textview will not be able to display images. textview 将无法显示图像。 You should use a webview.您应该使用 webview。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM