Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Html

public class Html
extends Object

java.lang.Object
   ↳ android.text.Html


This class processes HTML strings into displayable styled text. Not all HTML tags are supported.

Summary

Nested classes

interface Html.ImageGetter

Retrieves images for HTML <img> tags. 

interface Html.TagHandler

Is notified when HTML tags are encountered that the parser does not know how to interpret. 

Public methods

static String escapeHtml(CharSequence text)

Returns an HTML escaped representation of the given plain text.

static Spanned fromHtml(String source)

Returns displayable styled text from the provided HTML string.

static Spanned fromHtml(String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler)

Returns displayable styled text from the provided HTML string.

static String toHtml(Spanned text)

Returns an HTML representation of the provided Spanned text.

Inherited methods

From class java.lang.Object

Public methods

escapeHtml

Added in API level 16
String escapeHtml (CharSequence text)

Returns an HTML escaped representation of the given plain text.

Parameters
text CharSequence
Returns
String

fromHtml

Added in API level 1
Spanned fromHtml (String source)

Returns displayable styled text from the provided HTML string. Any <img> tags in the HTML will display as a generic replacement image which your program can then go through and replace with real images.

This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.

Parameters
source String
Returns
Spanned

fromHtml

Added in API level 1
Spanned fromHtml (String source, 
                Html.ImageGetter imageGetter, 
                Html.TagHandler tagHandler)

Returns displayable styled text from the provided HTML string. Any <img> tags in the HTML will use the specified ImageGetter to request a representation of the image (use null if you don't want this) and the specified TagHandler to handle unknown tags (specify null if you don't want this).

This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.

Parameters
source String
imageGetter Html.ImageGetter
tagHandler Html.TagHandler
Returns
Spanned

toHtml

Added in API level 1
String toHtml (Spanned text)

Returns an HTML representation of the provided Spanned text. A best effort is made to add HTML tags corresponding to spans. Also note that HTML metacharacters (such as "<" and "&") within the input text are escaped.

Parameters
text Spanned: input text to convert
Returns
String string containing input converted to HTML
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.