Strings and Styled Text

Strings, with optional simple formatting, can be stored and retrieved as resources. You can add formatting to your string by using three standard HTML tags: <b>, <i>, and <u>. To guarantee getting an unstyled string only (the raw text) call the toString() method of the retrieved CharSequence object. Methods that accept string resources should be able to process these styling tags.

If you want to retrieve the String represented by a resource ID, you can call the Context.getStringQ method.

Note: If you use an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other kind of enclosing quotes:

<string name="good_example">"This'll work"</string> <string name="good_example_2">This\'ll also work</string> <string name="bad_example">This won't work!</string>

<string name="bad_example_2">XML encodings won&apos;t work either!</string>

Source file format: XML file requiring a <?xml version="l.0" encoding="utf-8"?> declaration, and a root <resources> element containing one or more <string> tags.

Resource source file location: res/values/strings .xml (file name is arbitrary)

Compiled resource datatype: Resource pointer to a Java CharSequence.

0 0

Post a comment