Android TextView There are two main ways of changing fonts:
1. Html.fromhtml gets a spanned that is represented in Html format.
2, another way is directly constructed using a spanned.
To change the color and size of some fonts in a string at the same time, in the first way, html.fromhtml, with the font tag, unfortunately, the properties on the font in Android only support color and face, but size is not supported. Then completely using the font tag HTML, is not implemented.
If you use HTML to change the font size, you can try a label like <small> or
The second approach is simple and relatively easy to implement, as shown in the following example:
Colorstatelist redcolors = colorstatelist.valueof (0xffff0000); Spannablestringbuilder Spanbuilder = new Spannablestringbuilder ("This is a Test"); Style 0 is normal, and typeface.bold (bold) Typeface.italic (italic) and so on//size 0 is the original normal size Spanbuilder.setspan (new Textappearancespan (null, 0, redcolors, null), 0, 3, spanned.span_exclusive_inclusive); TextView tv_test = (TextView) Findviewbyid (r.id.tv_test); Tv_test.settext (Spanbuilder);
The effect is as follows
Android TextView also changes the color and size of some fonts in a string