string formatting in TextView

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

string formatting in TextView

Postby nbagade » Sat Jan 02, 2010 8:47 am

Hi all,
I have TextView .I am setting the text of textview using setText() method.

Now I have two line in my TextView.
both line displaying in the same font,color.
But i want both line should have different font and color.

How to do that?

anyone can help me?

Experienced Developer
Experienced Developer
Posts: 58
Joined: Fri Nov 20, 2009 7:49 am
Location: India


Postby jwei512 » Sat Jan 02, 2010 7:19 pm

The easiest way would probably be to just have two TextViews... one just right under the other.

However, if you need to keep it at just one TextView then you could try to style your string with HTML, for instance (call your TextView A):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  2. A.setText(Html.fromHtml("<font size = 4 color = 'red'> This is the contents of line one. </font> <font size = 5 color = 'yellow'> And this is the contents of line two. </font>"));
Parsed in 0.012 seconds, using GeSHi

And just try to play around with that.
- jwei
Examples, Code, and Tutorials
Senior Developer
Senior Developer
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby grzegorz.zajac » Sat Jan 02, 2010 7:24 pm

Posts: 39
Joined: Wed Feb 18, 2009 8:37 pm
Location: Krakow/Poland


Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests