在TextView中使用的大小HTML属性属性、大小、TextView、HTML

由网友(离别伊人憔)分享简介:我有以下几点:textView.setText(Html.fromHtml("Hello"));字符串'hello'不变成红色,但规模不会改变。The string 'Hello' does turn red but the size d...

我有以下几点:

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.

从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);
}
阅读全文

相关推荐

最新文章