Android Strings.xml escape character, attention to detail resolution

Source: Internet
Author: User

XML Escape character
The following is the numeric and string escape character for the XML marker
"(& #34; or ")
' (& #39; or ')
& (& #38; or &)
LT (<) (& #60; or &lt;)
GT (>) (& #62; or &gt;)



title:
For example, define the following string in String.xml,
<string name= "First" > Hello, Welcome to Eoeandroid community. Welcome to Here! </string>
I want to
Hello everyone, welcome to the Eoeandroid community.
Welcome to Here!
Two lines of the form output, how to do? Add \ n, look at the following:

<string name= "Hello" > Hello, Welcome to Eoeandroid community. \nwelcome to here! </string>



Space encoding in Android String.xml tips for adding spaces before and after
<string name= "Space" >& #160;& #160;& #160;& #160; I'll take a look. Spaces </string>
& #160; This represents the space.



1. When you encounter the following error, you need to sign the single quote with the escape character (\):
Description Resource Path location Type error:apostrophe not preceded by \ (in Search ' Titles) strings.xml
Simply modify the single quotation mark (') in the defined string to (\ ')


2. Variable text Format (%s) Hint:
Multiple annotations found at the line:
-Error:multiple substitutions specified in non-positional format; Did you mean to add the formatted= "false"
Attribute?
-Error:unexpected End Tag String
This is due to the new SDK (though it has never been used) with the new version of AAPT (Android Project compiler), this version of AAPT will compile more stringent than the old version, described in the latest Android development document section of the string, has explained how to set the%s and other symbols, you can click to see.
The simple workaround is to replace the variable format such as%s with%1 $ s, where%1 represents the first position of the variable, $s represented as a string type
For example:

<string name= "Welcome_messages" >your first Var is%1$s! You Second Var is%2$d.</string>

Android Strings.xml escape character, attention to detail resolution (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.