android - Is it possible to have multiple styles inside a TextView? -


is possible set multiple styles different pieces of text inside textview?

for instance, setting text follows:

tv.settext(line1 + "\n" + line2 + "\n" + word1 + "\t" + word2 + "\t" + word3); 

is possible have different style each text element? e.g., line1 bold, word1 italic, etc.

the developer guide's common tasks , how them in android includes selecting, highlighting, or styling portions of text:

// our edittext object. edittext vw = (edittext)findviewbyid(r.id.text);  // set edittext's text. vw.settext("italic, highlighted, bold.");  // if textview, do: // vw.settext("italic, highlighted, bold.", textview.buffertype.spannable); // force use spannable storage styles can attached. // or specify in xml.  // edittext's internal text storage spannable str = vw.gettext();  // create our span sections, , assign format each. str.setspan(new stylespan(android.graphics.typeface.italic), 0, 7, spannable.span_exclusive_exclusive); str.setspan(new backgroundcolorspan(0xffffff00), 8, 19, spannable.span_exclusive_exclusive); str.setspan(new stylespan(android.graphics.typeface.bold), 21, str.length() - 1, spannable.span_exclusive_exclusive); 

but uses explicit position numbers inside text. there cleaner way this?

in case, wondering how this, here's 1 way: (thanks mark again!)

mbox = new textview(context); mbox.settext(html.fromhtml("<b>" + title + "</b>" +  "<br />" +              "<small>" + description + "</small>" + "<br />" +              "<small>" + dateadded + "</small>")); 

for unofficial list of tags supported method, refer this link or question: which html tags supported android textview?


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -