zoukankan      html  css  js  c++  java
  • android 自定义html 标签

    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());
  • 相关阅读:
    (字符串)子串变位词
    反转链表 II
    翻转链表
    覆盖索引
    MySQL索引结构之Hash索引、full-text全文索引(面)
    MySQL索引结构之B+树索引(面)
    MYSQL 存储引擎(面)
    MySQL架构(面)
    如何在Linux Mint 20系统上安装Pip
    如何在CentOS 8系统服务器上安装Nginx
  • 原文地址:https://www.cnblogs.com/Ringer/p/4082872.html
Copyright © 2011-2022 走看看