简体   繁体   English

Android Studio资源字体文件夹

[英]Android Studio assets fonts folder

I am using Android Studio and I have the following code: 我正在使用Android Studio,并且具有以下代码:

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

Which executes perfectly when my .ttf file is under the assets folder. 当我的.ttf文件位于Assets文件夹下时,它可以完美执行。 But when I make a folder assets/fonts , move the .ttf file to that folder and try the following code: 但是,当我制作文件夹assets/fonts ,请将.ttf文件移动到该文件夹​​并尝试以下代码:

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. 我的资产文件夹位于app / src / main下。

This well work for me. 这对我来说很好。 I used getActivity() context to getAssets() from that context 我使用getActivity()上下文从该上下文getAssets()

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

My folder structure is like this 我的文件夹结构是这样的 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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