如何在android studio中创建自定义字体 [英] How to create custom fonts in android studio
问题描述
我需要为我的项目添加新字体我在哪里创建它在 android studio 中
I need to add new fonts to my project where do i create it in android studio
有人可以建议我是否在 android studio 的正确目录中创建它吗?
Can someone advise if i create it in the correct directory in android studio?
我尝试将 fonts 文件夹放在与 SRC 文件夹相同的位置,但没有成功
I tried putting the fonts folder same location as SRC folder but didn't work out
我的代码是
Typeface fontRobo = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Black.ttf");
viewTotalValue.setText(total.toString());
这是正确的吗?请指教
推荐答案
如果你使用android studio,你应该创建assets文件夹从右键单击
if you use android studio , you should create assets folder from right click at
应用程序--->新建--->文件夹--->资产文件夹
app ---> New --->Folder --->Assets Folder
选择目标到你的assets文件夹默认主
choose destination to your assets folder default main
在 assets 中创建一个名为 fonts 的目录,然后放置你的字体
create directory called fonts in assets then place your font
|assets
|-----------------fonts
|-------------------Roboto-Black.ttf
|java
|res
AndroidManifest.xml
最后使用这个代码
Typeface fontRobo = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Black.ttf");
viewTotalValue.setText(total.toString());
viewTotalValue.setTypeface(fontRobo );
这篇关于如何在android studio中创建自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!