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
//具体代码,可以是跳转页面,可以是弹出对话框,下面是跳转页面
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(mContext.getResources().getColor(R.color.blue));
ds.setUnderlineText(false);//是否显示下划线
//super.updateDrawState(ds);
}
}
}
String source = "<u>下划线标签</u><mytag><big>自定义的标签</big></mytag><i>斜体</i>"; textview.setText(Html.fromHtml(source, null, new MyTagHandler(this, 0xFF4D8C4D))); textview.setMovementMethod(LinkMovementMethod.getInstance());