HtmlCompat

public final class HtmlCompat
extends Object

java.lang.Object
   ↳ androidx.core.text.HtmlCompat


Backwards compatible version of Html.

Summary

Constants

int FROM_HTML_MODE_COMPACT

Flags for fromHtml(String, int, ImageGetter, TagHandler): Separate block-level elements with line breaks (single newline character) in between.

int FROM_HTML_MODE_LEGACY

Flags for fromHtml(String, int, ImageGetter, TagHandler): Separate block-level elements with blank lines (two newline characters) in between.

int FROM_HTML_OPTION_USE_CSS_COLORS

Flag indicating that CSS color values should be used instead of those defined in Color.

int FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE

Flag indicating that texts inside <blockquote> elements will be separated from other texts with one newline character by default.

int FROM_HTML_SEPARATOR_LINE_BREAK_DIV

Flag indicating that texts inside <div> elements will be separated from other texts with one newline character by default.

int FROM_HTML_SEPARATOR_LINE_BREAK_HEADING

Flag indicating that texts inside <h1>~<h6> elements will be separated from other texts with one newline character by default.

int FROM_HTML_SEPARATOR_LINE_BREAK_LIST

Flag indicating that texts inside <ul> elements will be separated from other texts with one newline character by default.

int FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM

Flag indicating that texts inside <li> elements will be separated from other texts with one newline character by default.

int FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH

Flag indicating that texts inside <p> elements will be separated from other texts with one newline character by default.

int TO_HTML_PARAGRAPH_LINES_CONSECUTIVE

Option for fromHtml(String, int): Wrap consecutive lines of text delimited by '\n' inside <p> elements.

int TO_HTML_PARAGRAPH_LINES_INDIVIDUAL

Option for fromHtml(String, int): Wrap each line of text delimited by '\n' inside a <p> or a <li> element.

Public methods

static Spanned fromHtml(String source, int flags)

Invokes Html.fromHtml(String, int) on API 24 and newer, otherwise flags are ignored and Html.fromHtml(String) is used.

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

Invokes Html.fromHtml(String, int, ImageGetter, TagHandler) on API 24 or newer, otherwise flags are ignored and Html.fromHtml(String, ImageGetter, TagHandler) is used.

static String toHtml(Spanned text, int options)

Invokes Html.toHtml(Spanned, int) on API 24 or newer, otherwise options are ignored and Html.toHtml(Spanned) is used.

Inherited methods

Constants

FROM_HTML_MODE_COMPACT

public static final int FROM_HTML_MODE_COMPACT

Flags for fromHtml(String, int, ImageGetter, TagHandler): Separate block-level elements with line breaks (single newline character) in between. This inverts the Spanned to HTML string conversion done with the option TO_HTML_PARAGRAPH_LINES_INDIVIDUAL.

Constant Value: 63 (0x0000003f)

FROM_HTML_MODE_LEGACY

public static final int FROM_HTML_MODE_LEGACY

Flags for fromHtml(String, int, ImageGetter, TagHandler): Separate block-level elements with blank lines (two newline characters) in between. This is the legacy behavior prior to N.

Constant Value: 0 (0x00000000)

FROM_HTML_OPTION_USE_CSS_COLORS

public static final int FROM_HTML_OPTION_USE_CSS_COLORS

Flag indicating that CSS color values should be used instead of those defined in Color.

Constant Value: 256 (0x00000100)

FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE

public static final int FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE

Flag indicating that texts inside <blockquote> elements will be separated from other texts with one newline character by default.

Constant Value: 32 (0x00000020)

FROM_HTML_SEPARATOR_LINE_BREAK_DIV

public static final int FROM_HTML_SEPARATOR_LINE_BREAK_DIV

Flag indicating that texts inside <div> elements will be separated from other texts with one newline character by default.

Constant Value: 16 (0x00000010)

FROM_HTML_SEPARATOR_LINE_BREAK_HEADING

public static final int FROM_HTML_SEPARATOR_LINE_BREAK_HEADING

Flag indicating that texts inside <h1>~<h6> elements will be separated from other texts with one newline character by default.

Constant Value: 2 (0x00000002)

FROM_HTML_SEPARATOR_LINE_BREAK_LIST

public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST

Flag indicating that texts inside <ul> elements will be separated from other texts with one newline character by default.

Constant Value: 8 (0x00000008)

FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM

public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM

Flag indicating that texts inside <li> elements will be separated from other texts with one newline character by default.

Constant Value: 4 (0x00000004)

FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH

public static final int FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH

Flag indicating that texts inside <p> elements will be separated from other texts with one newline character by default.

Constant Value: 1 (0x00000001)

TO_HTML_PARAGRAPH_LINES_CONSECUTIVE

public static final int TO_HTML_PARAGRAPH_LINES_CONSECUTIVE

Option for fromHtml(String, int): Wrap consecutive lines of text delimited by '\n' inside <p> elements. BulletSpans are ignored.

Constant Value: 0 (0x00000000)

TO_HTML_PARAGRAPH_LINES_INDIVIDUAL

public static final int TO_HTML_PARAGRAPH_LINES_INDIVIDUAL

Option for fromHtml(String, int): Wrap each line of text delimited by '\n' inside a <p> or a <li> element. This allows ParagraphStyles attached to be encoded as CSS styles within the corresponding <p> or <li> element.

Constant Value: 1 (0x00000001)

Public methods

fromHtml

public static Spanned fromHtml (String source, 
                int flags)

Invokes Html.fromHtml(String, int) on API 24 and newer, otherwise flags are ignored and Html.fromHtml(String) is used.

Parameters
source String

flags int

Returns
Spanned

fromHtml

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

Invokes Html.fromHtml(String, int, ImageGetter, TagHandler) on API 24 or newer, otherwise flags are ignored and Html.fromHtml(String, ImageGetter, TagHandler) is used.

Parameters
source String

flags int

imageGetter Html.ImageGetter

tagHandler Html.TagHandler

Returns
Spanned

toHtml

public static String toHtml (Spanned text, 
                int options)

Invokes Html.toHtml(Spanned, int) on API 24 or newer, otherwise options are ignored and Html.toHtml(Spanned) is used.

Parameters
text Spanned

options int

Returns
String