开发者

How to apply font size while rendering HTML code in Android or Java

开发者 https://www.devze.com 2023-04-12 17:20 出处:网络
My code is as follows. textView.setText(Html.fromHtml(\"6<sup>4</sup开发者_如何转开发>\"));

My code is as follows.

textView.setText(Html.fromHtml("6<sup>4</sup开发者_如何转开发>"));

The output is:

How to apply font size while rendering HTML code in Android or Java

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号