【问题标题】:Display a rich html textbox into a text view in android将富 html 文本框显示到 android 中的文本视图中
【发布时间】:2018-06-13 19:41:30
【问题描述】:

我在管理控制面板中有一个富文本视图(我不知道它的确切名称,但如下图所示),允许管理员编写产品描述

我有一个返回此文本框代码的 api,它为上述文本返回类似这样的内容:

&lt;ul&gt;&lt;li&gt;Simple product with user role price activited&lt;/li&gt;&lt;li&gt;Without flavor and size&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;<br>

我的问题是如何在我的 apk 中将这种富文本视图代码显示到文本视图中

编辑:我尝试使用fromHtml 方法,但它不起作用,可能是因为我有像ulli 这样的html 标签?

【问题讨论】:

标签: android android-layout textview


【解决方案1】:

您可以使用WebView 像这样显示您的 HTML 数据

val webView = findViewById<WebView>(R.id.my_webview)
val text = "<ul><li>Simple product with user role price activited</li><li>Without flavor and size<br></li></ul>"
webView.loadDataWithBaseURL(null, text, "text/html", "utf-8", null)

【讨论】:

  • 这拯救了我的一天,谢谢。另一个问题 Java 不允许直接存储长字符串,但在我的情况下,文本存储在 String 变量中,该变量从 API 获取其值,当字符串太长时,是否会抛出错误?
  • 我认为这应该不是问题,字符串最多可以有 2^31-1 个字符。唯一的限制是编译时字符串。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-01
  • 2011-09-23
  • 1970-01-01
  • 2019-06-10
  • 2013-01-23
  • 1970-01-01
相关资源
最近更新 更多