在TextView中使用size HTML属性

C0d*_*ack 10 android

我有以下内容:

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

字符串'Hello'确实变为红色,但大小不会改变.

好像只是忽略了size属性,有人知道为什么会这样吗?难道我做错了什么?

Tob*_*iug 14

大小属性似乎不起作用.

你可以使用<small>或<big> (多次增加效果)

您还可以使用<h1> 到<h6> (头只,即增加一个新行)

它的旧时尚,但它运作良好!

  • 我的上标标签如下:`&lt;small&gt; &lt;sup&gt; &lt;sup&gt; &lt;small&gt; &lt;small&gt; &lt;small&gt; 2 &lt;/ small&gt; &lt;/ small&gt; &lt;/ small&gt; &lt;/ small&gt; &lt;/ small&gt; &lt;/ sup&gt; &lt;/ sup &gt;` (2认同)

Ser*_*tov 10

是的,size属性只是被忽略了.仅考虑"颜色"和"面部"属性.

来自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);
}
Run Code Online (Sandbox Code Playgroud)