Recently need to display some hyperlinks in TextView, such as URL (click to jump), display network pictures and so on.
Tidy up as follows:
1. Display the URL and set it in the TextView that needs to display the URL hyperlink
Textview.settext (html.fromhtml (urlstring))
(URLString is identified by HTML syntax)
Versiontext.setmovementmethod (Linkmovementmethod.getinstance ());
The above sentence must be set, otherwise you will not be able to jump.
2. Display Network pictures
Textview.settext (html.fromhtml (urlstring, imggetter, NULL))
The HTML is called.
public static spanned fromhtml (String source, Imagegetter Imagegetter,
Taghandler Taghandler)
Need to pass in a imagegetter, similar to the following, to return a drawable:
Html.imagegetter imggetter = new Html.imagegetter () {
Public drawable getdrawable (String source) {
Drawable drawable = null;
URL url;
try {
url = new URL (source);
drawable = Drawable.createfromstream (Url.openstream (), ""); Get Network Images
} catch (Exception e) {
return null;
}
Drawable.setbounds (0, 0, drawable.getintrinsicwidth (), drawable
. Getintrinsicheight ());
return drawable;
}
};
This article from "Fangler" blog, declined reprint!