Using size HTML attribute in TextView

后端 未结 5 1030
花落未央
花落未央 2020-12-10 13:47

I have the following:

textView.setText(Html.fromHtml(\"Hello\"));

The string \'H

相关标签:
5条回答
  • 2020-12-10 14:34

    Look at Formatting and Styling on the android developpers site:
    http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling

    Or, on this old post of StackOverflow :
    Highlighting Text Color using Html.fromHtml() in Android?

    0 讨论(0)
  • 2020-12-10 14:37

    Sergey Gotov is right. The only way to change text size it to use h1 - h6 tags.

    EDIT: You can also implement TagHandler and use your own tags.

    0 讨论(0)
  • 2020-12-10 14:39

    Yes, size attribute just ignored. Only "color" and "face" attributes takes 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);
    }
    
    0 讨论(0)
  • 2020-12-10 14:44

    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 !

    0 讨论(0)
  • 2020-12-10 14:51

    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>"));
    
    0 讨论(0)
提交回复
热议问题