2012-06-23 36 views
8

您如何在Android XML文件中使用@作爲文本,因爲它具有特殊含義?我有一個TextView將只需持有文本@Android XML轉義符「@」符號

我想:

<TextView 
    android:id="@+id/at_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/account_name" 
    android:gravity="center_horizontal" 
    android:padding="3dip" 
    android:text="@" /> 

那當然沒有與錯誤

error: Error: No resource type specified (at 'text' with value '@').

所以我想它指向一個條目工作strings.xml這樣: <string name="at">@</string>並顯示錯誤:

error: Error: No resource type specified (at 'at' with value '@').

那麼我如何逃避@作爲TextView的文本?

回答

19

用這種方式..............

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

完美的感謝! – Jeshurun

+0

隨時歡迎!! ........ –

6
android:text="\@" 
      ^

,而不是

android:text="@"