Android:textview displaying Rich text information

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.