0

in my application I must use a custom type of font in a file .ttc . This file conteins different type of typeface (normal, bold, ...). With this code:

textDetails.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/font.ttc"));

I can take one type of typeface. There is a method to take all the typeface?

hasmet
  • 758
  • 3
  • 13
  • 32

2 Answers2

3

You can set the style to access the bold and italic typefaces:
http://developer.android.com/reference/android/widget/TextView.html#setTypeface(android.graphics.Typeface, int)

Try this:

textDetails.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/font.ttc"), Typeface.BOLD);
abeljus
  • 342
  • 1
  • 3
  • 10
0

You can load specific font from TTC file using Typeface.Builder (API level 26). This is a snippet from comments in the Typeface source code:

Typeface.Builder buidler = new Typeface.Builder(getAssets(), "your_font_file.ttc");
builder.setTtcIndex(2);  // Set index of font collection.
Typeface typeface = builder.build();

Only use setTtcIndex() method if you know the file is TTC.

Source: Android Source Code

Tricertops
  • 8,492
  • 1
  • 39
  • 41