2

I have a TextView in which the text foe an example is: "Android"

Now, I have to change the text style for first 3 char is "And" and except are in normal format.

I follow this SO link for the solution : Solution link

In which Typeface is using through below format and it is working fine

final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); 

but

I need to access the style / Typeface from Assets folder like: Parisienne-Regular.ttf

How can I pass the Assets file into this StyleSpan programatically ?


Edit 1;

<font size="..." color="..." face="...">

I found from this - link - but when I applied

tnew.setText(Html.fromHtml(" And"+"<font face='Parisienne'>"+ "a"+ "</font>"));

also not working.


Ans:

Typeface font1 = Typeface.createFromAsset(getAssets(), "Parisienne-Regular.ttf");
SS.setSpan (new CustomTypeFaceSpan("", font1), 3, 4,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
tnew.setText(SS);

And this LINK

Community
  • 1
  • 1
Akarsh M
  • 1,629
  • 2
  • 24
  • 47

1 Answers1

1

How can I pass the Assets file into this StyleSpan programatically ?

You don't. Instead, you need a different span class, one that is aware of your custom font. There are a few implementations of this floating around, including some on this StackOverflow question.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I'll check the link which you provide but I have seen your link http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html , there is tag . Can I use or not for "Parisienne" font family ? – Akarsh M Mar 21 '14 at 12:07
  • @AM: No, because `Html.fromHtml()` only knows about the built-in typefaces, because it works with `TypefaceSpan`, which only knows about the built-in typefaces. – CommonsWare Mar 21 '14 at 12:25