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

后端 未结 7 2032
眼角桃花
眼角桃花 2020-12-16 10:47

I\'m trying to use fonts in my project using Typeface. I copied the \"font.ttf\" into a folder named \"fonts\" inside \"assets\" folder. But eclipse do not allo

相关标签:
7条回答
  • 2020-12-16 10:50

    @ 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)

    0 讨论(0)
  • 2020-12-16 10:54

    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

    0 讨论(0)
  • 2020-12-16 11:04

    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

    0 讨论(0)
  • 2020-12-16 11:04

    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);
    
    0 讨论(0)
  • 2020-12-16 11:12

    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.

    0 讨论(0)
  • 2020-12-16 11:12

    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
    0 讨论(0)
提交回复
热议问题