android strings.xml逸出字元,注意細節解決 

來源:互聯網
上載者:User
 

XML逸出字元 
以下為XML標誌符的數字和字串轉義符 
"     (" 或 ") 
'     (' 或 ') 
&     (& 或 &) 
lt(<) (&#60; 或 &lt;) 
gt(>) (&#62; 或 &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">&#160;&#160;&#160;&#160;我來看空格</string> 
&#160; 這個就代表著空格
 

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>

XML逸出字元 
以下為XML標誌符的數字和字串轉義符 
"     (&#34; 或 &quot;) 
'     (&#39; 或 &apos;) 
&     (&#38; 或 &amp;) 
lt(<) (&#60; 或 &lt;) 
gt(>) (&#62; 或 &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">&#160;&#160;&#160;&#160;我來看空格</string> 
&#160; 這個就代表著空格
 

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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.