我在strings.xml文件中写了以下内容:
<string name="game_settings_dragNDropMove_checkBox">Move by Drag&Drop</string>
我得到了以下错误:
The reference to entity "Drop" must end with the ';' delimiter.
我怎么能写字符&在字符串。xml?
我在strings.xml文件中写了以下内容:
<string name="game_settings_dragNDropMove_checkBox">Move by Drag&Drop</string>
我得到了以下错误:
The reference to entity "Drop" must end with the ';' delimiter.
我怎么能写字符&在字符串。xml?
当前回答
它也可以把你的字符串的内容到一个XML CDATA,就像Android Studio为你做的,当你提取字符串资源
<弦name = " game_settings_dragNDropMove_checkBox > < ![CDATA[trag&drop Move]></字符集
其他回答
&在字符串中:
<string name="string_abc">Translate & Scan Objects</string>
输出将是:
翻译和扫描对象
对于特殊字符,我通常使用Unicode定义,例如“&”,如果我是正确的:\u0026。这里有一个很好的参考页面:http://jrgraphix.net/research/unicode_blocks.php?block=0
我发布这个是因为上面的编码都不适合我。
我发现用序列替换&作为XML字符串资源工作。如:
<string name="webLink"><a href="https://www.example.com?param1=option1&param2=option2">click here</a></string>
如果您想直接在xml中硬编码字符串,可以通过这种方式将其相加。
<TextView
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You & Me"
你可以这样写
<string name="you_me">You & Me<string>
输出:你和我