Android TextView show Html

来源:互联网 发布:印度同志聊天软件 编辑:程序博客网 时间:2024/05/01 18:42

HtmlTextView

Android use TextView show Html. Support and custom

由于Android不支持 font 标签的 size 所以自定义span标签来实现

Screenshot

Screenshot

java code

    /**     * span 标签 , 只识别了 font-size, color属性     */    String htmlSpan = "<p><span style=\"font-size:24px;color:#0000ff\"><font>我是Span 标题</font></span><span style=\"font-size:16px;color:#ff0000\"><font>+x</font></span></p><p><span style=\"font-size:16px;color:#999999\"><font>我是Span 内容</font></span></p>";    /**     * 自定义的fonts 标签     */    String htmlCustomFonts = "<p><fonts size='24' color='#ff0000'>我是标题自定义字号颜色<strike>删除线</strike></fonts></p>"+            "<p><fonts size='16' color='#00ee00'>我是内容自定义字号颜色</fonts></p>";    TextView mTextView;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        mTextView = (TextView) findViewById(R.id.textview);        mTextView.setLineSpacing(0, 0.7f);        mTextView.setText(Html.fromHtml(htmlSpan + htmlCustomFonts,  null, new MyTagHandler(this)));    }

style

<span style="font-size:16px;color:#666666;size:16px"><font>title</font></span><fonts size='24' color='#ff0000'>title</fonts>

源代码 https://github.com/helloHaifei/HtmlTextView

1 0
原创粉丝点击