简体   繁体   中英

Android textview html font size tag

I use <font size ="50"> tag in android textview like this

resultTextView.setText(Html.fromHtml("<font size='50' color='#337744'>Text Message</font>"));
resultTextView.setText(Html.fromHtml("<font size=\"50\" color='#337744'>Text Message</font>"));

but the problem is the color tag works but size tag doesn't work

In this blog http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

it is given that font size tag works. What's wrong in my code?

There is exact question Using size HTML attribute in TextView . It says it ignores the size. You can use use <small> for smaller text and so on. <font> only supports color and face attributes. see android.text.Html (on GrepCode) and How to apply font size while rendering HTML code in Android or Java and TextView with different textSize for more. Hope it helps in someway.

If you need only different size, you can use simple <small> or <big> and you can use it more times for one char.
Example: "clasic text is ok, but <big> bigger <big> is <big> better </big></big></big> " You can use <h1> etc. too, but here is problem with margins.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM