public class Bluetaghandler implements Html.taghandler {
private int sindex = 0;
private int eindex=0;
Private final Context Mcontext;
Public Bluetaghandler (Context context) {
Mcontext=context;
}
public void Handletag (Boolean opening, String tag, Editable output, XMLReader XMLReader) {
TODO auto-generated Method Stub
if (Tag.tolowercase (). Equals ("Blue")) {
if (opening) {
Sindex=output.length ();
}else {
Eindex=output.length ();
Output.setspan (New Bluespan (), Sindex, Eindex, spanned.span_exclusive_exclusive);
}
}
}
Private class Bluespan extends Clickablespan {
@Override
public void OnClick (View widget) {
TODO auto-generated Method Stub
Specific code, can be a jump page, can be a pop-up dialog box, the following is the jump page
}
@Override
public void Updatedrawstate (Textpaint ds) {
Ds.setcolor (Mcontext.getresources (). GetColor (R.color.blue));
Ds.setunderlinetext (false);//Whether the underline is displayed
Super.updatedrawstate (DS);
}
}
}
String Source = "<u> underline label </u><mytag><big> Custom Label </big></mytag><i> Italic </ I> "; Textview.settext (html.fromhtml (source, NULL, new Mytaghandler (this, 0xff4d8c4d))); Textview.setmovementmethod (Linkmovementmethod.getinstance ());
Android Custom HTML tags