如何插入"<<" TextView中的文字?

时间:2012-04-30 11:34:12

标签: java android xml

我需要插入“&lt;&lt;”在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 个答案:

答案 0 :(得分:18)

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

答案 1 :(得分:3)

您需要使用less-than XML转义字符。查看完整列表here

&lt;&lt;

答案 2 :(得分: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>