Assets folder in Android Studio?

丶灬走出姿态 提交于 2019-11-30 03:01:45

I am not sure if there has been any bug fixes since this was asked, but I am using the current structure for a project in Android Studio 0.5.2:

root-module
|--.idea
|--app
|----build
|----src
|------main
|--------assets
|----------SomeFont.ttc
|----------AnotherFont.otf
|--------java
|----------source code here
|--------res
|------AndroidManifest.xml
|----build.gradle

And then obtain it by calling

Typeface.createFromAsset(mContext.getResources().getAssets(), "SomeFont.ttc");

Word of caution though, there is a bug (https://code.google.com/p/android/issues/detail?id=9904) that prevents typefaces from being garbage collected properly. Use a singleton!

Create Assets folder Right click on app->>new->>Folder->>AssetsFolder like below image

Put your font inside this folder by just copy and paste. and use below code for example..

Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "YourFontName.ttf");
setTypeface(tf);
Md. Sajedul Karim

Simply follow this path:

File > New > folder > assets Folder

Here App must be selected before creating folder.

For more information see this answer

The assets folder should be placed under the root of the project. See here for more examples.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!