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 allow to compile it. It shows an error on fonts folder. What should I do?
我正在尝试使用Typeface在我的项目中使用字体。我将“font.ttf”复制到“assets”文件夹中名为“fonts”的文件夹中。但是eclipse不允许编译它。它在fonts文件夹中显示错误。我该怎么办?
The error I get is:
我得到的错误是:
invalid resource directory name fonts /NoRats/assets line 1 Android AAPT Problem
7 个解决方案
#1
36
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
.ttf文件位于 - > assets / fonts / LATINWD.TTF中
Please first clean your project then check again.
请先清理您的项目,然后再次检查。
Happy Coding.
#2
4
Put your Font File in Assest Folder,
将您的字体文件放在Assest文件夹中,
and in use Bellow Code for access.
并使用Bellow Code进行访问。
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
ttf文件位于 - > assets / fonts / Century Gothic.ttf中
#3
3
@ Android studio within Please check this code may be helpful to you
@Android studio内请检查此代码可能对您有所帮助
app/src/main/assets/your ttf file.
app / src / main / assets /你的ttf文件。
@ Add this code in activity.
@在活动中添加此代码。
Typeface typeface = Typeface.createFromAsset(getAssets(), ""); txt.setTypeface = (typeface)
字体字体= Typeface.createFromAsset(getAssets(),“”); txt.setTypeface =(字体)
@ Add this code in Adapter
@在Adapter中添加此代码
Typeface typeface = Typeface.createFromAsset(context.getAssets(), ""); txt.setTypeface = (typeface)
字体字体= Typeface.createFromAsset(context.getAssets(),“”); txt.setTypeface =(字体)
#4
2
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
如果仍未解决,请通过右键单击项目>构建路径> android>恢复默认值来配置构建路径
I hope this is helpful"
我希望这是有帮助的”
answer found at Error in Android project name in Eclipse
在Eclipse中的Android项目名称错误中找到答案
#5
0
As of Android Studio 1.5.1 you can:
从Android Studio 1.5.1开始,您可以:
- Right click on your
app
directory -
New
>Folder
(this is near the bottom of the list and is easy to miss) >Assets Folder
- In most cases you can leave the folder location as the default >
Finish
- Move your files into the newly created
assets
folder
右键单击您的app目录
新建>文件夹(位于列表底部附近,很容易错过)>资产文件夹
在大多数情况下,您可以将文件夹位置保留为默认值>完成
将文件移动到新创建的资源文件夹中
#6
0
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:
由于Android 8(API 26)中的字体组织和利用率发生了变化,现在建议将字体放入/ res / font /目录并使用以下命令访问它们:
(Typeface) ResourcesCompat.getFont(context, R.font.your_font_bold);
which will return a Typeface object you needed.
这将返回您需要的Typeface对象。
#7
0
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 ]
[注意:在我创建的上述patha中的assests目录中创建一个新目录(Folder)
Then put your ttf font file inside the fonts directory . You can set your font like this way :
然后将您的ttf字体文件放在fonts目录中。您可以这样设置字体:
Typeface anyName = Typeface.createFromAsset(Context,"fonts/yourFontFileName.ttf");
simpleTextView.setTypeface(anyName);
#1
36
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
.ttf文件位于 - > assets / fonts / LATINWD.TTF中
Please first clean your project then check again.
请先清理您的项目,然后再次检查。
Happy Coding.
#2
4
Put your Font File in Assest Folder,
将您的字体文件放在Assest文件夹中,
and in use Bellow Code for access.
并使用Bellow Code进行访问。
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
ttf文件位于 - > assets / fonts / Century Gothic.ttf中
#3
3
@ Android studio within Please check this code may be helpful to you
@Android studio内请检查此代码可能对您有所帮助
app/src/main/assets/your ttf file.
app / src / main / assets /你的ttf文件。
@ Add this code in activity.
@在活动中添加此代码。
Typeface typeface = Typeface.createFromAsset(getAssets(), ""); txt.setTypeface = (typeface)
字体字体= Typeface.createFromAsset(getAssets(),“”); txt.setTypeface =(字体)
@ Add this code in Adapter
@在Adapter中添加此代码
Typeface typeface = Typeface.createFromAsset(context.getAssets(), ""); txt.setTypeface = (typeface)
字体字体= Typeface.createFromAsset(context.getAssets(),“”); txt.setTypeface =(字体)
#4
2
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
如果仍未解决,请通过右键单击项目>构建路径> android>恢复默认值来配置构建路径
I hope this is helpful"
我希望这是有帮助的”
answer found at Error in Android project name in Eclipse
在Eclipse中的Android项目名称错误中找到答案
#5
0
As of Android Studio 1.5.1 you can:
从Android Studio 1.5.1开始,您可以:
- Right click on your
app
directory -
New
>Folder
(this is near the bottom of the list and is easy to miss) >Assets Folder
- In most cases you can leave the folder location as the default >
Finish
- Move your files into the newly created
assets
folder
右键单击您的app目录
新建>文件夹(位于列表底部附近,很容易错过)>资产文件夹
在大多数情况下,您可以将文件夹位置保留为默认值>完成
将文件移动到新创建的资源文件夹中
#6
0
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:
由于Android 8(API 26)中的字体组织和利用率发生了变化,现在建议将字体放入/ res / font /目录并使用以下命令访问它们:
(Typeface) ResourcesCompat.getFont(context, R.font.your_font_bold);
which will return a Typeface object you needed.
这将返回您需要的Typeface对象。
#7
0
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 ]
[注意:在我创建的上述patha中的assests目录中创建一个新目录(Folder)
Then put your ttf font file inside the fonts directory . You can set your font like this way :
然后将您的ttf字体文件放在fonts目录中。您可以这样设置字体:
Typeface anyName = Typeface.createFromAsset(Context,"fonts/yourFontFileName.ttf");
simpleTextView.setTypeface(anyName);