【问题标题】:How to insert "<<" text in TextView?如何在 TextView 中插入“<<”文本?
【发布时间】:2012-04-30 11:34:11
【问题描述】:

我需要在android:text = "&lt;&lt;" 中插入“

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文本中插入&amp;lt;&amp;lt;吗?

【问题讨论】:

  • 仅供参考,如果您在 Eclipse 中有 ADT 19,并且如果您为 android:text 键入 << 替换为 &amp;lt;&amp;lt;

标签: java android xml


【解决方案1】:

尝试&amp;lt;&amp;lt; 而不是&lt;&lt;。您必须转义这些字符,因为它们会影响您的 XML 布局。

【讨论】:

    【解决方案2】:

    您需要使用小于 XML 转义字符。查看完整列表here

    &lt;&lt;
    

    【讨论】:

      【解决方案3】:

      如建议所述,使用字符串赋值。在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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-22
        • 1970-01-01
        • 1970-01-01
        • 2016-02-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多