在TextView中使用的大小HTML属性 [英] Using size HTML attribute in TextView

查看:121
本文介绍了在TextView中使用的大小HTML属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下几点:

textView.setText(Html.fromHtml("<font color=\"red\" size=\"24\">Hello</font>"));

字符串'hello'不变成红色,但规模不会改变。

The string 'Hello' does turn red but the size does not change.

这是因为如果大小属性不理,没有人知道这是为什么?难道我做错了什么?

It is as if the size attribute is just ignored, does anyone know why this is? Am I doing something wrong?

推荐答案

是,大小属性只忽略。只有色和面子的属性考虑到了。

Yes, size attribute just ignored. Only "color" and "face" attributes takes into account.

从<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.3.4_r1/android/text/Html.java#621"><$c$c>Html类来源的:

private void handleStartTag(String tag, Attributes attributes) {
    if (tag.equalsIgnoreCase("br")) {
        // We don't need to handle this. TagSoup will ensure that there's a </br> for each <br>
        // so we can safely emite the linebreaks when we handle the close tag.
    }
    ...
    else if (tag.equalsIgnoreCase("font")) {
        startFont(mSpannableStringBuilder, attributes);
    }
    ...
}

private static void startFont(SpannableStringBuilder text,
                              Attributes attributes) {
    String color = attributes.getValue("", "color");
    String face = attributes.getValue("", "face");

    int len = text.length();
    text.setSpan(new Font(color, face), len, len, Spannable.SPAN_MARK_MARK);
}

这篇关于在TextView中使用的大小HTML属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆