Android: 来自 SQLite 的字符串不能在 Textview 中设置为 HTML
Android: String from SQLite can not be set as HTML in Textview
您好,我从后端 API 收到了 HTML 字符串格式的响应,我将文本视图作为 android 中的 HTML 使用:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
sinopsis.setText(Html.fromHtml(summaryText, Html.FROM_HTML_MODE_COMPACT));
}else{
sinopsis.setText(Html.fromHtml(summaryText));
}
问题是:
如果我将来自 API 的响应直接放入 Textview,则结果正确显示为 HTML 解析为 <br/>,
标签未显示为 html 代码
Hi this is example from API response
Thanks
但是如果我将结果作为字符串保存到 SQLite 中并进入显示为纯 html 代码的 Textview
Hi this is example from API response <br />Thanks
我不知道如何解决这个问题,请任何人帮助我。
已解决:我将一些 html 翻译成 Android 中的字符串函数,例如
翻译成 \n
您好,我从后端 API 收到了 HTML 字符串格式的响应,我将文本视图作为 android 中的 HTML 使用:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
sinopsis.setText(Html.fromHtml(summaryText, Html.FROM_HTML_MODE_COMPACT));
}else{
sinopsis.setText(Html.fromHtml(summaryText));
}
问题是:
如果我将来自 API 的响应直接放入 Textview,则结果正确显示为 HTML 解析为 <br/>,
标签未显示为 html 代码
Hi this is example from API response
Thanks
但是如果我将结果作为字符串保存到 SQLite 中并进入显示为纯 html 代码的 Textview
Hi this is example from API response <br />Thanks
已解决:我将一些 html 翻译成 Android 中的字符串函数,例如
翻译成 \n