【问题标题】:Android Html.fromhtml() + SpannableStringAndroid Html.fromhtml() + SpannableString
【发布时间】:2013-02-14 11:55:57
【问题描述】:

我在这个字符串中有html字符串和SpannableString,我把它们都放在TextView中,问题出在SpannableString中,Html.fromhtml()中没有显示。如何在Html.fromHtml() 中显示SpannableString?有可能吗?

    for(int index = 0; index < l.length; index++){ // have3d() return SpannableString
            x += "<font color=\"green\">" + have3d(title[index]) + " </font> <br />" + l[index] + "<br/><br/>";
            if(index == l.length-1){
                x += "<font color=\"green\">" + title[index] + " </font> <br />" + l[index] + "<br/>";
            }   
        }
mСinema.setText(Html.fromHtml(x));

【问题讨论】:

    标签: android html textview


    【解决方案1】:

    Html.fromHtml 返回一个Spanned,您可以通过这种方式将其转换为SpannableString:

    SpannableString text = new SpannableString(Html.fromHtml(x));
    

    然后通过调用来设置:

    mcinema.setText(text, BufferType.SPANNABLE);
    

    【讨论】:

    • x 包含什么?
    • 现在使用 HtmlCompat
    • 谢谢,这使我能够混合 html 和 spannable
    猜你喜欢
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多