1

I am using Android Studio and I have the following code:

Typeface customTypeface = Typeface.createFromAsset(getAssets(), "micra.ttf");

Which executes perfectly when my .ttf file is under the assets folder. But when I make a folder assets/fonts, move the .ttf file to that folder and try the following code:

Typeface customTypeface = Typeface.createFromAsset(getAssets(), "fonts/micra.ttf");

The application crashes.

What is the problem here? Should I replace the / symbol with something else? My assets folder is under app/src/main.

Zdravko Donev
  • 402
  • 5
  • 22
  • 2
    "The application crashes" -- use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Apr 14 '16 at 15:17

1 Answers1

6

This well work for me. I used getActivity() context to getAssets() from that context

Typeface tfBold = Typeface.createFromAsset(getActivity().getAssets(),
                "fonts/EntangledPlain.ttf");

My folder structure is like this enter image description here

Kathi
  • 1,061
  • 1
  • 16
  • 31
  • Wow... I added `.this` infront of `.getAssets()` as you showed and it worked! Thank you! Can you explain why it is not workig without `.this`? – Zdravko Donev Apr 14 '16 at 15:29
  • Because we need context of the assets folder, otherwise it dnt know where are our assets folder. If it helps accept the answer. – Kathi Apr 14 '16 at 15:32