1

In my layout, I have defined a TextView and have given it the id - textName.

Programmatically, I have set its text to My name is Blah. I was wondering if it is possible to programmatically increase the textsize of just Blah and not the whole TextView?

Ankush
  • 6,767
  • 8
  • 30
  • 42
  • put "my name is" and blah in separate textview – appukrb Nov 30 '12 at 10:09
  • I am not sure abt this. But this link might help: http://stackoverflow.com/a/1533512/1858914 –  Nov 30 '12 at 10:11
  • @appubala I thought about that but I don't want to add a separate textView as there are a lot of instances where I want to change the size of just one word in a TextView. Adding another textview to all of them will be tedious – Ankush Nov 30 '12 at 10:14

2 Answers2

4

Or simply using the Spannable class:

String text = textView.getText();
Spannable span = new SpannableString(text);
span.setSpan(new RelativeSizeSpan(1.5f), text.indexOf("Blah"), text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(span);
Adrián Rodríguez
  • 1,836
  • 15
  • 16
0

Yes!! you can do by formatting the string with HTML, refer https://stackoverflow.com/a/1533512/603233

like eg

String text = "<h5>My name is </h5><h1>Blah</h1>";
yourtextview.setText(Html.fromHtml(text));
Community
  • 1
  • 1
kumar_android
  • 2,273
  • 1
  • 21
  • 30