Reputation:
Friends,I am trying to set a text of variable size in my app, but I am not getting the desired result.
msgInside=(TextView)findViewById(R.id.textView2);
msgInside.setTextSize(30);
msgInside.setText("BIG MESSAGE");
msgInside.setTextSize(20);
msgInside.setText("SMALL MESSAGE");
I can only see the SMALL MESSAGE
, I need to see both the messages
Upvotes: 0
Views: 239
Reputation: 54322
You need to use spannable String for this purpose. Just try this,
TextView text=(TextView)findViewById(R.id.text);
Spannable span = new SpannableString("Hi this is Android");
span.setSpan(new RelativeSizeSpan(0.8f), 0 , 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setTextSize(20);
text.setText(span);
Upvotes: 3
Reputation: 5803
You are using the same textview
for your both texts. the second text will overwrite your first one.
For your desired result either use seperate texviews or use Spannable String to get seperate fonts, sizes etc.. in a single textview. This is a nice tutorial for Spannable String
Upvotes: 1
Reputation: 10623
yeah you can't use it double at a time, if u r ineterested in it then make a Reference object of that text view, i think u vl get something different and good.
Upvotes: 0
Reputation: 4139
use different textview for both text size message... its overright size of text if you use same textview for both message...
msgInside=(TextView)findViewById(R.id.textView2);
msgInside.setTextSize(30);
msgInside.setText("BIG MESSAGE");
msgInside3=(TextView)findViewById(R.id.textView3);
msgInside3.setTextSize(20);
msgInside3.setText("SMALL MESSAGE");
Thanks
Upvotes: 1