0

I am trying to import custom loaded fonts using a Typeface. In order to do this I must access my Assets. When I run the following code through my MainActivity class which extends Activity, it does not throw an error.

public class MainActivity extends Activity {
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/EuphoriaScript.otf"); 
}

When I run it through my View class, it throws an exception on the getAssets() method. I am guessing this is because it needs to be accessed in a different way. How can I do this?

Thanks

2
  • whats the issue i means any errors?
    – KOTIOS
    Jun 8, 2014 at 14:34
  • Are you sure you get an Exception ? Isn't it a compilation error ?
    – ben75
    Jun 8, 2014 at 14:34

1 Answer 1

1

The AssetManager is attached to your application package. So to get access to it you simply need a Context. Every view holds a reference to it's Context so to get an AssetManger from a View class simply do :

AssetManager assetManger = getContext().getAssets();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.