【问题标题】:How to write @ as string in Java [duplicate]如何在Java中将@写为字符串[重复]
【发布时间】:2019-02-01 06:09:37
【问题描述】:

如何在java中将@写成字符串。 当我写“@”时,它表示缺少资源类型 这是我的文本视图

<TextView 
android:height="wrap_content";
android:width="wrap_content";
android:text="@";
/>

【问题讨论】:

标签: java android string textview


【解决方案1】:

@ 符号用于 xml 文件中的资源引用。 建议的方法是定义与

相同的内部值/字符串资源
<string name="at_sign">"@"</string>
...

那就用吧

...
<TextView 
android:height="wrap_content"
android:width="wrap_content"
android:text="@string/at_sign"
/>

【讨论】:

    【解决方案2】:

    您可以使用 \u0040(unicode 字符)来代替 @。另一种解决方案:定义一个字符串资源并在您的TextView 中使用它。

    【讨论】:

      【解决方案3】:
      android:text="\@"
      

      使用反斜杠:

      <string name="at">\@</string>
      

      使用引号:

      <string name="at">"@"</string>
      

      【讨论】:

        【解决方案4】:

        您可以通过在此类特殊字符前简单添加反斜杠来完成此操作。它不仅适用于@,还适用于单引号、双引号、冒号等。

        希望这会有所帮助。把下面的代码,看看它是否有帮助。

        <TextView 
        android:height="wrap_content"
        android:width="wrap_content"
        android:text="\@"/>
        

        【讨论】:

          猜你喜欢
          • 2013-06-08
          • 2013-05-23
          • 2013-04-03
          • 2020-09-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多