One, loading HTML code
String html= "<a href=\" http://www.111cn.net "> Baidu </a>;";
Textview.setmovementmethod (Linkmovementmethod.getinstance ());//Allow hyperlinks to click Jump to Browser
Textview.settext (html.fromhtml (Html));
Second, load SRC label
1. Load local picture
String html= "Textview.settext (html.fromhtml (Html, New Html.imagegetter () {
@Override
Public drawable getdrawable (String source) {
Drawable drawable = null;
try {
drawable = Drawable.createfromstream (new URL (source). OpenStream (), NULL);
Drawable.setbounds (0, 0, drawable.getintrinsicwidth (), Drawable.getintrinsicheight ());
catch (IOException e) {
E.printstacktrace ();
}
return drawable;
}
},null));
Note: file:/don't forget to add
HTML also has a three-parameter fronhtml method, with three parameters: String Source (the path to the picture resource), Imagegetter Imagegetter (the object that implements the Imagegetter class), Taghandler Taghandler (I don't know what to do, but it's OK to set it to null)
Imagegetter class is a static interface of the HTML class, there is a method getdrawable, the return value is drawable, the function is to obtain the picture drawable
drawable = Drawable.createfromstream (new URL (source). OpenStream (), NULL);
This code, one thing to say, do not use a lot of people on the Internet to use:
drawable= Drawable.createfrompath (source);
A filenotfound error may be reported.
2. Load Network picture
The HTML code is similar to the previous, the path to the network image of the address on the line
Like what:
String html= "But Imagegetter's Getdrawable method needs to change:
Here use the Piccsso frame load network picture, not the classmate can go to Baidu
Private class Myimagegetter implements Html.imagegetter {
Private urldrawable urldrawable = null;
@Override
Public drawable getdrawable (final String source) {
urldrawable = new Urldrawable ();
Picasso.with. Load (source). into (new Target () {
@Override
public void onbitmaploaded (Bitmap Bitmap, picasso.loadedfrom from) {
Urldrawable.bitmap = bitmap;
Urldrawable.setbounds (0, 0, bitmap.getwidth (), Bitmap.getheight ());
Textview.settext (Textview.gettext ())//Without this sentence does not show the picture, for unknown reasons
}
@Override
public void onbitmapfailed (drawable errordrawable) {
}
@Override
public void Onprepareload (drawable placeholderdrawable) {
}
});
return urldrawable;
}
}
Urldrawable class:
/**
* Created by the Administrator on 2016/6/28 0028.
*/
public class Urldrawable extends Bitmapdrawable {
Public Bitmap Bitmap;
@Override
public void Draw (Canvas Canvas) {
Super.draw (canvas);
if (bitmap!= null) {
Canvas.drawbitmap (bitmap, 0, 0, Getpaint ());
}
}
}
The method is invoked as follows:
Textview.settext (html.fromhtml (Html, New Myimagegetter (), null));