Html
open class Html
kotlin.Any | |
↳ | android.text.Html |
This class processes HTML strings into displayable styled text. Not all HTML tags are supported.
Summary
Nested classes | |
---|---|
abstract |
Retrieves images for HTML <img> tags. |
abstract |
Is notified when HTML tags are encountered that the parser does not know how to interpret. |
Constants | |
---|---|
static Int |
Flags for |
static Int |
Flags for |
static Int |
Flag indicating that CSS color values should be used instead of those defined in |
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 |
static Int |
Option for |
Public methods | |
---|---|
open static String! |
escapeHtml(text: CharSequence!) Returns an HTML escaped representation of the given plain text. |
open static Spanned! |
Returns displayable styled text from the provided HTML string with the legacy flags |
open static Spanned! |
Returns displayable styled text from the provided HTML string. |
open static Spanned! |
fromHtml(source: String!, imageGetter: Html.ImageGetter!, tagHandler: Html.TagHandler!) Returns displayable styled text from the provided HTML string with the legacy flags |
open static Spanned! |
fromHtml(source: String!, flags: Int, imageGetter: Html.ImageGetter!, tagHandler: Html.TagHandler!) Returns displayable styled text from the provided HTML string. |
open static String! | |
open static String! |
Returns an HTML representation of the provided Spanned text. |
Constants
FROM_HTML_MODE_COMPACT
static val FROM_HTML_MODE_COMPACT: Int
Flags for fromHtml(java.lang.String,int,android.text.Html.ImageGetter,android.text.Html.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: 63
FROM_HTML_MODE_LEGACY
static val FROM_HTML_MODE_LEGACY: Int
Flags for fromHtml(java.lang.String,int,android.text.Html.ImageGetter,android.text.Html.TagHandler)
: Separate block-level elements with blank lines (two newline characters) in between. This is the legacy behavior prior to N.
Value: 0
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: 256
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: 32
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: 16
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: 2
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: 8
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: 4
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: 1
TO_HTML_PARAGRAPH_LINES_CONSECUTIVE
static val TO_HTML_PARAGRAPH_LINES_CONSECUTIVE: Int
Option for toHtml(android.text.Spanned,int)
: Wrap consecutive lines of text delimited by '\n' inside <p> elements. BulletSpan
s are ignored.
Value: 0
TO_HTML_PARAGRAPH_LINES_INDIVIDUAL
static val TO_HTML_PARAGRAPH_LINES_INDIVIDUAL: Int
Option for toHtml(android.text.Spanned,int)
: Wrap each line of text delimited by '\n' inside a <p> or a <li> element. This allows ParagraphStyle
s attached to be encoded as CSS styles within the corresponding <p> or <li> element.
Value: 1
Public methods
escapeHtml
open static fun escapeHtml(text: CharSequence!): String!
Returns an HTML escaped representation of the given plain text.
fromHtml
open static funfromHtml(source: String!): Spanned!
Deprecated: use fromHtml(java.lang.String,int)
instead.
Returns displayable styled text from the provided HTML string with the legacy flags FROM_HTML_MODE_LEGACY
.
fromHtml
open static fun fromHtml(
source: String!,
flags: Int
): Spanned!
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.
fromHtml
open static funfromHtml(
source: String!,
imageGetter: Html.ImageGetter!,
tagHandler: Html.TagHandler!
): Spanned!
Deprecated: use fromHtml(java.lang.String,int,android.text.Html.ImageGetter,android.text.Html.TagHandler)
instead.
Returns displayable styled text from the provided HTML string with the legacy flags FROM_HTML_MODE_LEGACY
.
fromHtml
open static fun fromHtml(
source: String!,
flags: Int,
imageGetter: Html.ImageGetter!,
tagHandler: Html.TagHandler!
): Spanned!
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.
toHtml
open static funtoHtml(text: Spanned!): String!
Deprecated: use toHtml(android.text.Spanned,int)
instead.
toHtml
open static fun toHtml(
text: Spanned!,
option: Int
): String!
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 |
option |
Int: one of TO_HTML_PARAGRAPH_LINES_CONSECUTIVE or TO_HTML_PARAGRAPH_LINES_INDIVIDUAL |
Return | |
---|---|
String! |
string containing input converted to HTML |