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?

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

Top

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
  1.  
  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>"));
  3.  
  4.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


And just try to play around with that.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
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

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

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests