天天看點

android string.xml 轉譯、特殊字元問題

在編輯 string.xml 檔案的時候,字元之間的空格用 space 鍵是能顯示出效果的的,但是字元後面如果需要添加空格,直接 space 鍵是不管用的,此時 空格應該用  來表示;

如:

<string name="score">score :  </string>  ======》 這樣就能顯示出冒号後面的 空格

http://lanyan-lan.iteye.com/blog/1561500

xml轉義字元 

以下為xml标志符的數字和字元串轉義符 

"     (" 或 ") 

'     (' 或 ') 

&     (& 或 &) 

lt(<) (< 或 <) 

gt(>) (> 或 >) 

如題: 

比如:在string.xml中定義如下一個字元串, 

<string name="first">大家好,歡迎來到eoeandroid社群。welcome to here!</string> 

我想以 

大家好,歡迎來到eoeandroid社群。 

welcome to here! 

兩行的形式輸出,如何做?加\n,看下面: 

<string name="hello">大家好,歡迎來到eoeandroid社群。\nwelcome to here!</string> 

android中的空格編碼 string.xml前後加空格的技巧 

<string name="space">    我來看空格</string> 

  這個就代表着空格 

1. 遇到如下錯誤的時候說明你需要在單引号簽名加轉義字元(\): 

description resource path location type error: apostrophe not preceded by \ (in search' titles) strings.xml 

隻要将定義的字元串中的單引号('), 修改為(\')即可 

2. 變量文本格式(%s)提示: 

multiple annotations found at this line: 

- error: multiple substitutions specified in non-positional format; did you mean to add the formatted="false" 

attribute? 

- error: unexpected end tag string 

這是由于新的sdk(雖然從沒用過老的)采用了新版本的aapt(android項目編譯器), 這個版本的aapt編譯起來會比老版本更加的嚴格, 在android最新的開發文檔中描述string的部分,已經說明了如何去設定 %s 等符号, 可以點選去看. 

簡單解決方法就是:把%s之類的變量格式替換成%1$s, %1表示第一個位置的變量, $s表示為字元串類型 

例如: 

<string name="welcome_messages">your first var is %1$s! you second var is %2$d.</string> 

http://songfantasy.iteye.com/blog/1562029