Using size HTML attribute in TextView

Try this one,Its working for me,use small,big key words

TextView mBox = (TextView) findViewById(R.id.txt);
mBox.setText(Html.fromHtml("<font color=#cc0029>" + "<b>"
        + "Hiiiiiiiiii" + "</b>" + "<br />" + "<small>" + "description"
        + "</small>" + "<br />" + "<small>" + "DateAdded" + "</small>"));

Size attribute seems not working.

You can use <small> or <big> (multiple times to increase the effect)

You can also use <h1> to <h6> (Header only, i.e. add a new line)

Its old-fashion, but it works well !


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

From Html class sources:

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);
}

Tags:

Android