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

后端 未结 2 1472
抹茶落季
抹茶落季 2020-12-16 15:09

My code is as follows.

textView.setText(Html.fromHtml(\"64\"));

The output is:

相关标签:
2条回答
  • 2020-12-16 15:34

    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 讨论(0)
  • 2020-12-16 15:35

    According to android.text.Html (on GrepCode), you may use <small> for smaller text, as <font> only supports color and face attributes.

    0 讨论(0)
提交回复
热议问题