[英]Android show HTML on TextView method fromHtml
I am trying to display HTML in my textview. 我正在尝试在textview中显示HTML。 I found this page and it says to use .fromHtml.
我找到此页面 ,并说要使用.fromHtml。 I get an error when I try to use it
尝试使用时出现错误
TextView tvAbout = (TextView) window.findViewById(R.id.tvAbout);
Spanned about_text = Html.fromHtml(R.string.about_text);
tvAbout.setText(about_text);
Eclipse suggests I use toHtml
. Eclipse建议我使用
toHtml
。 When I do that it then suggest I use fromHtml
. 当我这样做时,建议我使用
fromHtml
。 Suggestions? 有什么建议吗?
Try this.. 尝试这个..
Use getString
before getting from string.xml
从
string.xml
获取之前使用getString
Spanned about_text = Html.fromHtml(getString(R.string.about_text));
The Html.fromHtml
expects a string parameter, while the parameter you have provided "R.string.about_text" is an integer ID. Html.fromHtml
需要一个字符串参数,而您提供的“ R.string.about_text”参数是一个整数ID。 Thats the reason for your error. 多数民众赞成在您的错误原因。
So follow Hariharan's answer to correct it to get the text from that ID. 因此,请按照Hariharan的答案进行更正,以从该ID中获取文本。
getString(R.string.about_text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.