0

So is it possible to change text size of part of the text in textview dynamically Let's say we have a method that does that...what am I missing...I want to make x variable twice as big as y...they are string btw...

private void Data_transfer() {

    test3.setText( x + "   " + y);
    }
user1480742
  • 145
  • 12

2 Answers2

2

You can use the Spannable type with a TextView to set multiple styles in one field.

In your case, you can do this like so, using the fromHtml() method which generates a Spannable string:

test3.setText( Html.fromHtml( "<font size='10'>" + x + "</font>   <font size='5'>" + y + "</font>" ) );

And you can, of course, change 10 and 5 to whatever values you like.

Community
  • 1
  • 1
Cat
  • 66,919
  • 24
  • 133
  • 141
0
private void Data_transfer() {

TextView tv = (TextView)findViewById(R.id.textView1);
tv.setText("Welcome to android");

}
Furqi
  • 2,403
  • 1
  • 26
  • 32
  • Ok I know that part but what if your text consists of 3 variables: a,b,c ..a = Welcome, b = to, c = android...and I want different sizes for every each of them...what then? – user1480742 Aug 09 '12 at 18:50