【发布时间】:2019-08-06 11:37:08
【问题描述】:
我的 Android 应用程序有几个屏幕,用户可以在其中点击一个按钮,并在 DialogFragment 中弹出帮助文本。目前这些 DF 的文本存储在 strings.xml 中,如下所示:
<string name="help_content">
<![CDATA[<h1>Welcome</h1>
<p>Here is some helpful information</p>]]></string>
显然,这让我可以为文本添加样式以使其看起来更好。
在几个地方,我想解释一些图标的作用,我想包括图标的图像,所以我想做这样的事情:
<string name="help_content">
<![CDATA[<h1>Welcome</h1>
<p><img src="path/to/icon1"> This is what Icon 1 does</p>
<p><img src="path/to/icon2"> This is what Icon 2 does</p>]]></string>
有没有办法包含图像,以便它们使用应用程序中的实际图像?即类似于getResources().getDrawable(R.drawable.icon_1) 或@drawable/icon_1 之类的东西,可以从CDATA 中引用。这两个我都试过了,但是出现红色错误线。
【问题讨论】:
-
你是如何使用这个 HTML 的?你把它放在
WebView吗?您是否使用HtmlCompat.fromHtml()并将其放入TextView?还是您想直接通过@string/help_content将其放入TextView? -
检查this
-
我直接在 TextView 中使用它,使用 @string/help_content
标签: android android-resources cdata