this may blunder,but need know... :) iam develeoping android application,in in want display 2 type face in single textview , found this 1 useful,a custom typeface span extends typeface span, per understanding , creating spannable follows using 2 words
string firstword = "first "; string secondword = "second"; // create new spannable 2 strings spannable spannable = new spannablestring(firstword+secondword); then sets 2 type face words using our custom span
// set custom typeface span on section of spannable object spannable.setspan( new customtypefacespan("sans-serif",custom_typeface), 0, firstword.length(), spannable.span_exclusive_exclusive); spannable.setspan( new customtypefacespan("sans-serif",second_custom_typeface), rstword.length(), secondword.length(), spannable.span_exclusive_exclusive); now question, have large amount of text if able put spans directly in text more easy ,is possible put spans directly text put <b>bold </b> need use custom typeface span <typeface1> sample </typeface1> <typeface2> doc </typeface2>.
what need is, directly apply change text set span text
is possible, if possible need write span in text,how can achieve this.. or compleatly wrong ?
thank all
very late answer asked pretty easy.
for instance, lets want change between quotation marks italic font.
string s = "\"hello name edward\" hola, nombre es edward"; pattern p = pattern.compile("\"([^\"]*)\""); matcher m = p.matcher(text); spannable spannable = new spannablestring(s); while (m.find()) { int textlocation = text.indexof(m.group(1)); // set custom typeface span on section of spannable object spannable.setspan( new customtypefacespan("sans-serif",my_italic_font), textlocation-1, textlocation + m.group(1).length(),spannable.span_exclusive_exclusive); // set text of textview spannable object textview textbox = (textview) v.findviewbyid(r.id.cardtextbox); } textbox.settext( spannable ); result of s be
"hello name edward" hola, nombre es edward
now instead of quotation marks use regex pattern tags <b>bold </b>;
and remove tags afterwards simple .replace();
Comments
Post a Comment