【问题标题】:Android show HTML on TextView method fromHtmlAndroid 在来自 HTML 的 TextView 方法上显示 HTML
【发布时间】:2014-03-29 15:38:52
【问题描述】:
我正在尝试在我的文本视图中显示 HTML。我找到了这个page,它说要使用.fromHtml。尝试使用时出现错误
TextView tvAbout = (TextView) window.findViewById(R.id.tvAbout);
Spanned about_text = Html.fromHtml(R.string.about_text);
tvAbout.setText(about_text);
Eclipse 建议我使用toHtml。当我这样做时,它建议我使用fromHtml。有什么建议吗?
【问题讨论】:
标签:
android
html
textview
【解决方案1】:
试试这个..
在从string.xml 获取之前使用getString
Spanned about_text = Html.fromHtml(getString(R.string.about_text));
【解决方案2】:
Html.fromHtml 需要一个字符串参数,而您提供的参数“R.string.about_text”是一个整数 ID。这就是你的错误的原因。
因此,请按照 Hariharan 的答案进行更正以从该 ID 中获取文本。
getString(R.string.about_text)