2

Is there an easy way to change the font of the first letter in a string or word in Android? For example, I'd like to use an extravagant gothic font for the first letter of every word in a title, and then have the rest of the title in a smaller font.

Using custom imported fonts, so I'm not sure if HTML tags would work.

Muz
  • 5,866
  • 3
  • 47
  • 65
  • Maybe this can help you: http://stackoverflow.com/questions/7036685/is-it-possible-to-have-multiple-typefaces-in-the-same-textview – antoniom Aug 17 '12 at 08:34

1 Answers1

2

My best guess would be to use a Spannable for the first letter with a different typeface, using a TypefaceSpan. Example.

If you want to use your own custom font, you should extend TypefaceSpan.

Community
  • 1
  • 1
Benito Bertoli
  • 25,285
  • 12
  • 54
  • 61
  • Seems good so far, but any ideas how to detect the First Letter Of Every Word In A String? – Muz Aug 17 '12 at 09:33
  • @Muz your first letter is at `string.charAt(0);` –  Aug 17 '12 at 09:40
  • @Aman That detects the first letter of the string, but not the first letter in each word in the string. – Muz Aug 17 '12 at 09:42
  • @Muz , the the only way I can think of is use a tokenizer to separate each word change your `TypefaceSpan` and append it back, or do some type of parsing to detect `letter` after space. –  Aug 17 '12 at 09:48