Explanation of Html class for Android Development
During Android development, Html classes are often ignored. This class is actually very simple, that is, parsing HTML Tag text into common style text. Let me take a look at the specific introduction of this class.
Class Structure:
Java. lang. Object |
? |
Android. text. Html |
Class Overview:
This class is used to process HTML strings and convert them into printable style text. But not all HTML tags are supported.
Public method:
Simply put, it should have four methods:
Public Methods |
Static String |
EscapeHtml (CharSequence text) Returns Html Escape characters from a given representative name. |
Static Spanned |
FromHtml (String source) Returns the displayed style text from the Html string. |
Static Spanned |
FromHtml (String source, Html. ImageGetter imageGetter, Html. TagHandler tagHandler) Returns the displayed style text from the Html string. |
Static String |
ToHtml (Spanned text) Convert text to Html. |
Method description:
Public static Spanned fromHtml (String source, Html. ImageGetter imageGetter, Html. TagHandler tagHandler)
Parameters:
Source: a string containing Html.
ImageGetter: imageGetter object. When tags are parsed, the system calls the getDrawable method of the imageGetter object and passes the src attribute value to the getDrawable method. The specific meaning of the src attribute must be determined in the getDrawable method. The getDrawable method returns a Drawable object. We can obtain image resources from res/drawable resources, assets resources, SD cards, and networks and package them into Drawable objects.
TagHandler: The TagHandler object. The handleTag method of the object is called when the system does not process a tag. However, this parameter is not commonly used. If not, you can set it to null.
To be continued ......