[英]Adding costum font to android in font family xml
In the android guides for Fonts in XML , they give the example of font family XML you create by adding: 在XML字体的android指南中 ,他们通过添加以下内容提供了您创建的字体系列XML的示例:
android:font="@font/lobster_regular"
机器人:字体= “@字体/ lobster_regular”
Which I think its the font you added to your assets/font folder. 我认为它是您添加到素材资源/字体文件夹中的字体。 But when i try it I don't get it why it isn't able to find the font I've added.
但是当我尝试它时,我不明白为什么它找不到我添加的字体。 It only fins sans, serif and mono-space.
它只在无衬线,衬线和等宽处鳍。 Anyone have a clue what it might be the problem?
有人知道这可能是什么问题吗?
I know there are other ways to add a custom font, but due to the material calendar that I want to use, I need it to define in the styles XML, only way to customize it. 我知道还有其他添加自定义字体的方法,但是由于要使用的材质日历,我需要在XML样式中定义它,这是自定义字体的唯一方法。 I tried
calligraphy lib
, but does not help. 我尝试了
calligraphy lib
,但没有帮助。
Using typeface you easily set font family 使用字体,您可以轻松设置字体系列
Typeface type = Typeface.createFromAsset(getAssets(),
"fonts/fontname");
now set this typeface to your textview 现在将此字体设置为您的textview
tv.setTypeface(type);
Add this to your activity code: 将此添加到您的活动代码中:
TextView tv = (TextView) findViewById(R.id.appname);
Typeface face = Typeface.createFromAsset(getAssets(),
"fonts/fontname");
tv.setTypeface(face);
Note that for this you'll have to create a fonts folder at app/src/main/assets
请注意,为此,您必须在
app/src/main/assets
创建一个字体文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.