android - 字符串资源中的 HTML

标签 android android-xml

我正在尝试通过使用 WebView 并使用 HTML 格式化字符串资源来证明文本的合理性,如在某些示例中所见:

     <string name="dTxt">
    <html>
        <head></head>
        <bodystyle text-align:justify=""><body> Lorem ipsum dolor sit amet, consectetur  adipiscing elit. 
   Nunc pellentesque, urna nec hendrerit pellentesque, risus massa </body>
   </bodystyle>
   </html>
   </string>

ADT 拒绝解析字符串文档并出现以下错误:

  W/ResourceType( 2612): Bad XML block: header size 296 or total size 6144712 is larger than data size 0

这里有什么问题吗?

最佳答案

njzk2是对的,<和>是禁止直接作为字符串使用的。但是,您可以将 HTML 包装在 CDATA 中:

<string name="dTxt">
<![CDATA[
    <html>
        <head></head>
        <bodystyle text-align:justify="">
            <body> Lorem ipsum dolor sit amet, consectetur  adipiscing elit. 
                Nunc pellentesque, urna nec hendrerit pellentesque, risus massa 
            </body>
        </bodystyle>
   </html>
]]>
</string>

关于android - 字符串资源中的 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18146981/

相关文章:

android - 从 gradle build 控制 list 元数据

android - 创建自定义表单 java android

android - 如何自动应用父级的样式?

android - 调用 XML 可绘制对象的 XML 按钮

android - 如何获得从 View 到手机底部的距离?

android - Buttonstyle - 尺寸类型不允许

android - 如何根据升序整数对sqlite表进行排序?

android - 我/flutter (17109): Another exception was thrown: A RenderFlex overflowed by 80 pixels on the right

android - 图像按钮上的单击效果

android - 有人能告诉我为什么我的工具栏中的文本背景是白色的吗?