简体   繁体   中英

Android Studio assets fonts folder

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.

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 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM