Use string resource in layout resource
Description
Once you've defined the strings as resources, you can set them directly on a view.
Example
The following example shows an
example where an HTML string is set as the text content of a TextView
.
The following code is for string.xml
.
<resources>
<string name="simple_string">simple string</string>
<string name="tagged_string">
Hello <b><i>Slanted Android</i></b>, You are bold.
</string>
</resources>
The following code is for layout.xml
.
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/tagged_string"/>
The TextView
automatically realizes that
this string is an HTML string and honors its
formatting accordingly.