Different colors in one TextView

Put your problem here if it does not fit any of the other categories.

Different colors in one TextView

Postby thedeftone » Tue Apr 15, 2008 6:22 pm

Hi

If I created a TevtView with 3 Lines via TextView.setLines(3). Would it be possible to have each line in a different color?
The Reason why I'm asking is that i want to have a multi-color, multil-ine Button ;)
thedeftone
Junior Developer
Junior Developer
 
Posts: 14
Joined: Wed Apr 09, 2008 7:51 pm

Top

Postby khoinguyen » Sat Apr 19, 2008 6:19 am

It's my problem to..I dont know in textview can have multi color lines or not.
I try to use webView ^^
khoinguyen
Freshman
Freshman
 
Posts: 5
Joined: Sat Mar 22, 2008 4:16 pm

Postby thedeftone » Sat Apr 19, 2008 10:16 am

I yesterday found out that you somehow can style the text with HTML. I think that's the key for it. :D
thedeftone
Junior Developer
Junior Developer
 
Posts: 14
Joined: Wed Apr 09, 2008 7:51 pm

Postby rock_win » Mon Apr 21, 2008 10:06 am

thedeftone,

u can give <b> and <i> while strings are defined in the strings.xml, but is there a way i can retain them when i try to display it through code too.

like
--String.xml
<string name="one"><b>Test</b></string>

--in code

editSetText(editText.getText()+"ing");

When i try the above thing the formatting mentioned in the string.xml is lost.

Can you please point my to the api segment, where i can find more info on this html text
rock_win
Junior Developer
Junior Developer
 
Posts: 11
Joined: Mon Jan 21, 2008 4:24 pm

Postby michael_g_hu » Tue Apr 22, 2008 2:46 am

this is easy. Below is the sample:
TextView tv = new TextView(xx);
SpannableStringBuilder text = new SpannableStringBuilder("xxxxxx");
text.setspan(new ForegroundColorSpan(Color.RED),
startIndex, len,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(text);
the string from startIndex and to startIndex +len will be the color red.
michael_g_hu
Developer
Developer
 
Posts: 35
Joined: Fri Mar 21, 2008 9:46 am

Postby michael_g_hu » Tue Apr 22, 2008 3:00 am

Sorry for the mistake, the argument len is the end index of the text string , not the lenght from the startIndex
michael_g_hu
Developer
Developer
 
Posts: 35
Joined: Fri Mar 21, 2008 9:46 am

Top

Postby thedeftone » Tue Apr 22, 2008 7:42 pm

rock_win wrote:Can you please point my to the api segment, where i can find more info on this html text


http://code.google.com/android/reference/android/text/Html.html

This is what I meant, does that mean that I can write HTML and decode it with this class?
Or how ist this class meant to be? :D
thedeftone
Junior Developer
Junior Developer
 
Posts: 14
Joined: Wed Apr 09, 2008 7:51 pm

Spannable of android

Postby bhavani » Tue Jul 06, 2010 9:59 am

Is there any body worked with android spannable class. If it is the case please help me. How to get the bold text into un bold ,means after appling the bold property with sannable, how to remove after selecting the bold text and clicking on the button.Please help me

Regards,
Bhavani.G
hi..
bhavani
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jan 20, 2010 12:29 pm
Location: india

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests