The Android Developer Challenge is back! Submit your idea before December 2.

HtmlCompat

class HtmlCompat
kotlin.Any
   ↳ androidx.core.text.HtmlCompat

Backwards compatible version of Html.

Summary

Constants

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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(@NonNull source: String, flags: Int)

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

static Spanned
fromHtml(@NonNull source: String, flags: Int, @Nullable imageGetter: ImageGetter?, @Nullable 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(@NonNull text: Spanned, options: Int)

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

Constants

FROM_HTML_MODE_COMPACT

static val FROM_HTML_MODE_COMPACT: Int

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.

Value: Html.FROM_HTML_MODE_COMPACT

FROM_HTML_MODE_LEGACY

static val FROM_HTML_MODE_LEGACY: Int

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.

Value: Html.FROM_HTML_MODE_LEGACY

FROM_HTML_OPTION_USE_CSS_COLORS

static val FROM_HTML_OPTION_USE_CSS_COLORS: Int

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

Value: Html.FROM_HTML_OPTION_USE_CSS_COLORS

FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE

static val FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE: Int

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

Value: Html.FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE

FROM_HTML_SEPARATOR_LINE_BREAK_DIV

static val FROM_HTML_SEPARATOR_LINE_BREAK_DIV: Int

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

Value: Html.FROM_HTML_SEPARATOR_LINE_BREAK_DIV

FROM_HTML_SEPARATOR_LINE_BREAK_HEADING

static val FROM_HTML_SEPARATOR_LINE_BREAK_HEADING: Int

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

Value: Html.FROM_HTML_SEPARATOR_LINE_BREAK_HEADING

FROM_HTML_SEPARATOR_LINE_BREAK_LIST

static val FROM_HTML_SEPARATOR_LINE_BREAK_LIST: Int

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

Value: Html.FROM_HTML_SEPARATOR_LINE_BREAK_LIST

FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM

static val FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM: Int

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

Value: Html.FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM

FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH

static val FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH: Int

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

Value: Html.FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH

TO_HTML_PARAGRAPH_LINES_CONSECUTIVE

static val TO_HTML_PARAGRAPH_LINES_CONSECUTIVE: Int

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

Value: Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE

TO_HTML_PARAGRAPH_LINES_INDIVIDUAL

static val TO_HTML_PARAGRAPH_LINES_INDIVIDUAL: Int

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.

Value: Html.TO_HTML_PARAGRAPH_LINES_INDIVIDUAL

Public methods

fromHtml

@NonNull static fun fromHtml(@NonNull source: String, flags: Int): Spanned

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

fromHtml

@NonNull static fun fromHtml(@NonNull source: String, flags: Int, @Nullable imageGetter: ImageGetter?, @Nullable tagHandler: TagHandler?): Spanned

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

toHtml

@NonNull static fun toHtml(@NonNull text: Spanned, options: Int): String

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