如何在TextView中插入"<<"文本?

12

我需要在android:text = "<<"中插入"<<",但是会出现问题:

Multiple annotations found at this line:
    - [I18N] Hardcoded string "<<", should use @string resource
    - The value of attribute "android:text" associated with an element type "Button" must not contain the '<' 
     character.
你能告诉我如何在 xml 文件的 TextView 文本中插入 << 吗?

3
如果您在Eclipse中使用ADT 19并在android:text中键入<<,它会自动用&lt;&lt;替换<< - Paresh Mayani
3个回答

21

请使用&lt;&lt;替代<<。您需要转义这些字符,因为它们会影响您的XML布局。


4

您需要使用小于符号的XML转义字符。在此处可以查看完整列表

&lt;&lt;

2

按照建议,使用字符串赋值。在strings.xml中创建一个字符串,像这样:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    ..
    <string name="chevrons">&lt;&lt;</string>

</resources>

然后将TextView指向它,像这样:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="20sp" 
    android:text="@string/chevrons"
>
</TextView>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接