HtmlCompat

Added in 1.1.0

public final class HtmlCompat


Backwards compatible version of Html.

Summary

Constants

static final int

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

static final int

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

static final int

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

static final int

Flag indicating that texts inside

elements will be separated from other texts with one newline character by default.

static final int

Flag indicating that texts inside

elements will be separated from other texts with one newline character by default.

static final int

Flag indicating that texts inside

~

elements will be separated from other texts with one newline character by default.

static final int

Flag indicating that texts inside

    elements will be separated from other texts with one newline character by default.

static final int

Flag indicating that texts inside

  • elements will be separated from other texts with one newline character by default.

  • static final int

    Flag indicating that texts inside

    elements will be separated from other texts with one newline character by default.

    static final int

    Option for fromHtml: Wrap consecutive lines of text delimited by '\n' inside

    elements.

    static final int

    Option for fromHtml: Wrap each line of text delimited by '\n' inside a

    or a

  • element.

  • Public methods

    static @NonNull Spanned
    fromHtml(@NonNull String source, int flags)

    Invokes fromHtml on API 24 and newer, otherwise flags are ignored and fromHtml is used.

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

    Invokes fromHtml on API 24 or newer, otherwise flags are ignored and fromHtml is used.

    static @NonNull String
    toHtml(@NonNull Spanned text, int options)

    Invokes toHtml on API 24 or newer, otherwise options are ignored and toHtml is used.

    Constants

    FROM_HTML_MODE_COMPACT

    Added in 1.1.0
    public static final int FROM_HTML_MODE_COMPACT = 63

    Flags for fromHtml: 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.

    FROM_HTML_MODE_LEGACY

    Added in 1.1.0
    public static final int FROM_HTML_MODE_LEGACY = 0

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

    FROM_HTML_OPTION_USE_CSS_COLORS

    Added in 1.1.0
    public static final int FROM_HTML_OPTION_USE_CSS_COLORS = 256

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

    FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE

    Added in 1.1.0
    public static final int FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE = 32

    Flag indicating that texts inside

    elements will be separated from other texts with one newline character by default.

    FROM_HTML_SEPARATOR_LINE_BREAK_DIV

    Added in 1.1.0
    public static final int FROM_HTML_SEPARATOR_LINE_BREAK_DIV = 16

    Flag indicating that texts inside

    elements will be separated from other texts with one newline character by default.

    FROM_HTML_SEPARATOR_LINE_BREAK_HEADING

    Added in 1.1.0
    public static final int FROM_HTML_SEPARATOR_LINE_BREAK_HEADING = 2

    Flag indicating that texts inside

    ~

    elements will be separated from other texts with one newline character by default.

    FROM_HTML_SEPARATOR_LINE_BREAK_LIST

    Added in 1.1.0
    public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST = 8

    Flag indicating that texts inside

      elements will be separated from other texts with one newline character by default.

    FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM

    Added in 1.1.0
    public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM = 4

    Flag indicating that texts inside

  • elements will be separated from other texts with one newline character by default.

  • FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH

    Added in 1.1.0
    public static final int FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH = 1

    Flag indicating that texts inside

    elements will be separated from other texts with one newline character by default.

    TO_HTML_PARAGRAPH_LINES_CONSECUTIVE

    Added in 1.1.0
    public static final int TO_HTML_PARAGRAPH_LINES_CONSECUTIVE = 0

    Option for fromHtml: Wrap consecutive lines of text delimited by '\n' inside

    elements. BulletSpans are ignored.

    TO_HTML_PARAGRAPH_LINES_INDIVIDUAL

    Added in 1.1.0
    public static final int TO_HTML_PARAGRAPH_LINES_INDIVIDUAL = 1

    Option for fromHtml: Wrap each line of text delimited by '\n' inside a

    or a

  • element. This allows ParagraphStyles attached to be encoded as CSS styles within the corresponding

    or

  • element.

  • Public methods

    fromHtml

    Added in 1.1.0
    public static @NonNull Spanned fromHtml(@NonNull String source, int flags)

    Invokes fromHtml on API 24 and newer, otherwise flags are ignored and fromHtml is used.

    fromHtml

    Added in 1.1.0
    public static @NonNull Spanned fromHtml(
        @NonNull String source,
        int flags,
        @Nullable Html.ImageGetter imageGetter,
        @Nullable Html.TagHandler tagHandler
    )

    Invokes fromHtml on API 24 or newer, otherwise flags are ignored and fromHtml is used.

    toHtml

    Added in 1.1.0
    public static @NonNull String toHtml(@NonNull Spanned text, int options)

    Invokes toHtml on API 24 or newer, otherwise options are ignored and toHtml is used.