Textview in Android supports some HTML format tags. This includes common font size and color settings and text links. It is easy to use. You only need to use HTML class conversion. For example:
Textview. settext (html. fromhtml (STR ));
I,The text in textview has different colors.
Import android. text. HTML; textview T3 = (textview) findviewbyid (R. id. text3); t3.settext (HTML. fromhtml ("<B> text3: </B> text with a "+" <a href = \ "http://www.google.com \"> link </a> "+" created in the Java source code using HTML. "));
II,Textview: display images in HTML files
We know that we want textview to parse and display HTMLCode. Available
Spanned text = html. fromhtml (source); TV. settext (text );
This is easy to use.
However, how can we make textview display the image of the <image> node in HTML?
We can see that fromhtml has another refactoring:
Fromhtml (string source, HTML. imagegetter, HTML. taghandler)
Implement imagegetter to display the image:
Imagegetter imggetter = new HTML. imagegetter () {@ override public drawable getdrawable (string source) {drawable = NULL; drawable = drawable. createfrompath (source); // or fetch it from the URL // important drawable. setbounds (0, 0, drawable. getintrinsicwidth (), drawable. getintrinsicheight (); Return drawable ;}};
As for taghandler, we do not need to use it here. You can directly transmit null.