Search code examples
androidtextview

How to change the text size in side the text view in android?


I have textview inside that i want to change the text size of text in middle of the text like below

enter image description here


Solution

  • Use Html.fromHtml(str):

    String str="<font size =\"20\"><B>Bold</B> <br/> Then Normal Text<br/>
                             <i>Then Italic</i> </font>" +
                           "<br/> <font color=\"green\" >this is simple sentence </font>" +
                           "<br/> <font face=\"verdana\" >this is simple sentence </font>"+
                           "<br/><br/><br/><br/><a>this is simple sentence</a>";
    Spanned strHtml= Html.fromHtml(str);
    
    TextView tv = (TextView)findViewById(R.id.textView);
    tv.setText(strHtml);
    

    Or you can use SpannableString.