问题
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?
回答1:
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.
回答2:
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.
回答3:
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>"));
来源:https://stackoverflow.com/questions/18295881/android-textview-html-font-size-tag