2

I want increase font size of some part of the string before set to text view. Means My string is "Hello Stack over flow". Then I want font size of over is larger than other words and its bold.

user2799407
  • 549
  • 1
  • 6
  • 16

3 Answers3

7

Do something like below,

 String str="<small>Hello Stack</small><big>Over</big>flow";
 textview.setText(Html.fromHtml(str));
Spring Breaker
  • 8,233
  • 3
  • 36
  • 60
6

You can use a SpannableString

Example :

TextView tv = new TextView(this);
String string= "Hello";
String title="MyTitle";
SpannableString ss1=  new SpannableString(string);
ss1.setSpan(new RelativeSizeSpan(2f), 0, ss1.length(), 0);
tv.append(ss1);
tv.append(title);
setContentView(tv);

Snap

enter image description here

You may also check

Using size HTML attribute in TextView

Searching for supported html tags

http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

http://bigknol.com/android-supported-html-tags-textview-string/

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

you can use html string to make some part bold for example

private String getHtmlText(String boldString,String restString){

    String htmlString = "<b>" +boldString +"</b> "  + restString;

    return htmlString;
}

and then setText using Html.fromHtml(htmlString) like

  yourTextView.setText(Html.fromHtml(getHtmlText(textBold,textNormal)));
maddy d
  • 1,530
  • 2
  • 12
  • 23