首页 > 解决方案 > 如何在Android(TextView)中将带有HTML代码的双引号显示为文本?

问题描述

我想在教程应用程序中将 HTML 代码显示为文本

字符串.xml

<string name="p1"><![CDATA[<html>\n<title> Font tag Example </title>\n<body>\n<font face="arial" size="1" color="blue"> WELCOME </font> <br>\n <font size="2" color="cyan"> WELCOME </font> <br>\n <pre>\n This text uses pre tag and preserves nextline and spaces\n </pre>\n </body>\n </html>]]></string>

prog1.xml

<TextView
    android:id="@+id/p1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="15dp"
    android:textSize="18sp"
    android:text="@string/p1" />

显示不带“”,需要显示带“”双引号

不带双引号显示

要求这样显示

标签: androidhtmlandroid-layoutandroid-studio

解决方案


在文本视图中显示双引号(“”)使用这些中的任何一个

  • &quot;
  • \"

这是官方的android网站
https://developer.android.com/guide/topics/resources/string-resource


推荐阅读