android - Use different typefaces for the same TextView with HTL formatting -


i know how specify custom typeface textview. of now, application using 1 custom font, splitted in 2 ttf files. 1 regular characters , toher 1 bold characters.

now, able use both inone textview html.fromhtml(). works system fonts, should able own typeface. currently, bold characters drawn regular font , fake bold text text paint quite ugly.

any idea ?

thanks

if want use multiple custom fonts within single textview:

use following code:(i'm using bangla , tamil font)

  textview txt = (textview) findviewbyid(r.id.custom_fonts);           txt.settextsize(30);         typeface font = typeface.createfromasset(getassets(), "akshar.ttf");         typeface font2 = typeface.createfromasset(getassets(), "bangla.ttf");            spannablestringbuilder ss = new spannablestringbuilder("আমারநல்வரவு");         ss.setspan (new customtypefacespan("", font2), 0, 4,spanned.span_exclusive_inclusive);         ss.setspan (new customtypefacespan("", font), 4, 11,spanned.span_exclusive_inclusive);         txt.settext(ss); 

the outcome is:

enter image description here


customtypefacespan class:

package my.app; import android.graphics.paint; import android.graphics.typeface; import android.text.textpaint; import android.text.style.typefacespan;  public class customtypefacespan extends typefacespan {  private final typeface newtype;  public customtypefacespan(string family, typeface type) {     super(family);     newtype = type; }  @override public void updatedrawstate(textpaint ds) {     applycustomtypeface(ds, newtype); }  @override public void updatemeasurestate(textpaint paint) {     applycustomtypeface(paint, newtype); }  private static void applycustomtypeface(paint paint, typeface tf) {     int oldstyle;     typeface old = paint.gettypeface();     if (old == null) {         oldstyle = 0;     } else {         oldstyle = old.getstyle();     }      int fake = oldstyle & ~tf.getstyle();     if ((fake & typeface.bold) != 0) {         paint.setfakeboldtext(true);     }      if ((fake & typeface.italic) != 0) {         paint.settextskewx(-0.25f);     }      paint.settypeface(tf); } } 

reference


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -