HTML strings

Description

Android allows child XML elements such as <b>, <i>, and other simple text-formatting HTML within the <string> node.

Example

You can use this compound HTML string to style the text before painting in a text view.

The following XML string resource file needs to be in the /res/values subdirectory.


<resources>
    <string name="simple_string">simple string</string>
     <string name="tagged_string">
         Hello <b><i>Android</i></b>, You are bold.
     </string>
</resources>


The following java code shows how to use the html-formatted string.

             
String simpleString = activity.getString(R.string.simple_string);
textView.setText(simpleString);//  w  w  w  .  j  a  va  2 s. c o m

String htmlTaggedString = activity.getString(R.string.tagged_string);

Spanned textSpan = android.text.Html.fromHtml(htmlTaggedString);

textView.setText(textSpan);




















Home »
  Android »
    Android Basics »




Hello Android
Resources
Activity
Calendar
Camera
Contact
Content Provider
Database
Hardware
Intent
Location
Media
Network
Notification
Preference
Sensor
Service
SMS