Книга: Beginning Android
Plain Strings
Plain Strings
Generally speaking, all you need to have for plain strings is an XML file in the res/values
directory (typically named res/values/strings.xml
), with a resources root element, and one child string element for each string you wish to encode as a resource. The string element takes a name attribute, which is the unique name for this string, and a single text element containing the text of the string:
<resources>
<string name="quick">The quick brown fox...</string>
<string name="laughs">He who laughs last...</string>
</resources>
The only tricky part is if the string value contains a quote (") or an apostrophe ('). In those cases, you will want to escape those values, by preceding them with a backslash (e.g., These are the times that try men's souls
). Or, if it is just an apostrophe, you could enclose the value in quotes (e.g., "These are the times that try men's souls."
).
You can then reference this string from a layout file (as @string/...
, where the ellipsis is the unique name — e.g., @string/laughs
). Or you can get the string from your Java code by calling getString()
with the resource ID of the string resource, that being the unique name prefixed with R.string.
(e.g., getString(R.string.quick)
).
- Strings
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces
- More on Strings
- 13.6.3. strings
- uucico Complains That the Site Is Already Locked
- Chapter 8 Strings and Regular Expressions
- 10. Numbers, Characters, and Strings
- Complaints, боль и удовольствие
- Пример 12-26. "Расширенная" команда strings
- Strings in Binary Files
- Strings in SGI STL
- Элемент ‹connectionStrings›