How to apply font size while rendering HTML code in Android or Java
My code is as follows.
textView.setText(Html.fromHtml("6<sup>4</sup开发者_如何转开发>"));
The output is:
Now I want to change the size of 4, so I applied the font as follows, but font is not getting applied.
textView.setText(Html.fromHtml("6<sup><font size="-2">4</font></sup>"));
How do I fix this problem?
According to android.text.Html (on GrepCode), you may use <small>
for smaller text, as <font>
only supports color and face attributes.
I found the solution of how to set different size in a single TextView.
At first define a TextView and connect it to xml and follow this.
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="15sp" //define the size as per your requirement
android:textColor="#F2F2F2" />
Then go to Java page
TextView txt=(TextView)findViewById(R.id.txt);
txt.setText(Html.fromHtml("<big><b>Xyzd</b></big><small>.com</small>"));
However, the big tag automatically increases 2-4 sp size and the small tag reduces 2-4 sp.
Increase and decrease your text size from xml android:textSize="15sp"
.
It works just check it.
精彩评论