Where should I put the “ttf” files in an Android project?

穿精又带淫゛_ 提交于 2019-11-29 02:56:34
Nikhil

Please check this link, it may be helpful to you.


OR


use below code.

Typeface tf = Typeface.createFromAsset(this.getAssets(),"fonts/LATINWD.TTF");
txt1.setTypeface(tf);

.ttf file is in --> assets/fonts/LATINWD.TTF

Please first clean your project then check again.

Happy Coding.

Hardik Gajjar

Put your Font File in Assest Folder,

and in use Bellow Code for access.

Typeface tf=Typeface.createFromAsset(getAssets(),"fonts/Century Gothic.ttf");


textview=(TextView)findViewById(R.id.textviewone);
       textview.setTypeface(tf);

ttf file is in --> assets/fonts/Century Gothic.ttf

@ Android studio within Please check this code may be helpful to you

app/src/main/assets/your ttf file.

@ Add this code in activity.

Typeface typeface = Typeface.createFromAsset(getAssets(), ""); txt.setTypeface = (typeface)

@ Add this code in Adapter

Typeface typeface = Typeface.createFromAsset(context.getAssets(), ""); txt.setTypeface = (typeface)

dinesh707

Thank you everybody for answers. But i managed to make it work by doing following

"clean your project with Project menu > clean tab then build your project

If it's still unsolved, configure build path by right click on project > build path > android > restore default

I hope this is helpful"

answer found at Error in Android project name in Eclipse

As of Android Studio 1.5.1 you can:

  1. Right click on your app directory
  2. New > Folder (this is near the bottom of the list and is easy to miss) > Assets Folder
  3. In most cases you can leave the folder location as the default > Finish
  4. Move your files into the newly created assets folder

Since font organization and utilization has changes in Android 8 (API 26), it is now recommended to put your fonts into /res/font/ directory and access them with:

(Typeface) ResourcesCompat.getFont(context, R.font.your_font_bold);

which will return a Typeface object you needed.

You should put fonts inside this path

\app\src\main\assets\fonts

[Note : Create a new directory(Folder) inside the assests directory in the above patha i have created ]

Then put your ttf font file inside the fonts directory . You can set your font like this way :

Typeface anyName  = Typeface.createFromAsset(Context,"fonts/yourFontFileName.ttf");

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