我在strings.xml文件中写了以下内容:

<string name="game_settings_dragNDropMove_checkBox">Move by Drag&Drop</string>

我得到了以下错误:

The reference to entity "Drop" must end with the ';' delimiter.

我怎么能写字符&在字符串。xml?


当前回答

即使你的问题已经回答了,我仍然想告诉更多这样的实体。 这些都是html实体,所以在android中你可以这样写:

如下所示:

& with &amp;
> with &gt;
< with &lt;
" with &quot;, &ldquo; or &rdquo;
' with &apos;, &lsquo; or &rsquo;
} with &#125;

其他回答

我发布这个是因为上面的编码都不适合我。

我发现用序列替换&#38;作为XML字符串资源工作。如:

<string name="webLink"><a href="https://www.example.com?param1=option1&#38;param2=option2">click here</a></string>

Mac和Android工作室用户:

在string.xml或布局中键入你的字符,如&,并选择“选项”和“返回”键。 请参考截图

应该是这样的:

<string name="game_settings_dragNDropMove_checkBox">Move by Drag&amp;Drop</string>

这是我的一个问题,我的解决方法如下:使用&gt;对于>,&lt;对于<,&For &,"'" For ', &quot For \"\"

它也可以把你的字符串的内容到一个XML CDATA,就像Android Studio为你做的,当你提取字符串资源

<弦name = " game_settings_dragNDropMove_checkBox > < ![CDATA[trag&drop Move]></字符集