0

I need to apply font for alpha numeric characters only. All special characters must be drawn with degault font. Is this possible in Android if yes then how ?

1 Answers1

0

See if this does match your needs

You can let all upper and lower case characters, as well as numbers have different styles, sizes, colors, ...

[EDIT 1]

You can:

mBox = new TextView(context);
mBox.setText(Html.fromHtml("<b>" + title + "</b>" +  "<br />" + 
    "<small>" + description + "</small>" + "<br />" + 
    "<small>" + DateAdded + "</small>"));

where you can use the HTML tag font-face

[EDIT 2]

Here's an example of using two different fonts on the same Spannable

link 1

Here it is shown how to load several different fonts from assets

link 2

By combining these two (and adding your code to compare each character to see if it falls in a case or the other) you should be able to get the results you're pursuing

I hope I helped.

Community
  • 1
  • 1
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Hi Klaus66, This is not the one I am looking for. I have a custom font which supports only alpha numeric characters, for special characters, it is showing some other symbols. So here what i want is, What ever text my textview has, it should be displayed in such a way that only apha numeric characters displayed in custom font and special characters must be displayed with default font. But still thanks for your reply – Kapil Londhe Dec 18 '13 at 07:14
  • So, have a look [here](http://stackoverflow.com/questions/1529068/is-it-possible-to-have-multiple-styles-inside-a-textview). It has all you need. – Phantômaxx Dec 18 '13 at 08:06
  • Hey Klaus66 I guess you are not getting my requirements. What ever you are saying is just applying different styles to part of strings and all. I will be having n numbers of strings and i want to apply .ttf font to all the textViews used in the application. But it should only apply font to Alphanumeric characters and not the special characters. – Kapil Londhe Dec 18 '13 at 16:00
  • Well, so, you didn't read my second link!! There are AT LEAST two ways to do that... – Phantômaxx Dec 18 '13 at 16:29
  • Really? If so, what about: mBox.setText(Html.fromHtml("ABC+-+")); – Phantômaxx Dec 18 '13 at 19:04
  • Agreed to your point sir... But my font is custom font and i have a .ttf font present in assets folder. How can i apply that font while saying ? Let me know if there is any way to read the font in Html.fromHtml from assets – Kapil Londhe Dec 18 '13 at 20:06
  • I see... but maybe you can do the opposite: use your custom fon for the whole string... and then use (the default Roboto or Droid font) only on those characters which arent alphanumeric - see [this](http://stackoverflow.com/questions/12128331/how-to-change-fontfamily-of-textview-in-android) – Phantômaxx Dec 18 '13 at 20:16
  • Maybe you'll find the [EDIT 2] section of my answer interesting. – Phantômaxx Dec 18 '13 at 20:30
  • Cheers! man!.. I didn't think of it... You are great. I will surely do this. Thanks once again – Kapil Londhe Dec 19 '13 at 03:17
  • Tried doing this... But it is taking the custom font which has been set using setTypeFace There is no effect of Html.fromHtml("ABC+-+") on the text in the TextView – Kapil Londhe Dec 19 '13 at 06:45
  • Boom!!!!! It worked.. man... Just few syntax issue with html code... text and it worked Cheers!! Thanks once again.. – Kapil Londhe Dec 19 '13 at 08:17