2012-04-10 42 views
0

在Eclipse中使用默認佈局處理新的Android項目時,我發現了一個我確定記錄的行爲......某處...但我無法識別出位置。TextView拋出顯示字符串資源的設計器錯誤

當strings.xml中「你好」資源包含一個字符串,它看起來像這樣:

<string name="hello" 
    formatted="false">@BrandingName: Branding phrase ending with @ 
    </string> 

Eclipse的設計師的ArrayIndexOutOfBounds拋出一個解決資源價值。我猜這是因爲它不知道如何正確地轉義「@BrandingName:」的某個部分?使用TextView正確顯示它的方法是什麼?

僅供參考TextView的節點如下:

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" /> 

回答

0

用「@」啓動字符串資源會在設計器中導致錯誤。領先的空間將防止該錯誤。前導空格看起來並沒有在TextView中呈現。

1

嘗試使用實體,而不是「@」 - &#64

還有,如果你想爲你的字符串格式化,你可以這樣使用CDATA:

<string name="hello"><![CDATA[ @BrandingName: Branding phrase ending with @ ]]></string> 
+0

@ BrandingName:以@結尾的品牌短語產生相同的異常。只要在@之前有一個空格,使用CDATA的配方就可以工作。很明顯,用@試圖啓動一個字符串資源,以間接的方式解析資源... – 2012-04-10 22:05:00

+0

+ + +1爲了讓我足夠接近以找到領先錯誤(至少它看起來像一個錯誤) – 2012-04-23 04:31:09