在字体系列xml中将costum字体添加到android

时间:2018-03-13 11:04:45

标签: android android-layout android-studio android-calendar android-fonts

Fonts in XML的Android指南中,他们通过添加以下内容给出了您创建的字体系列XML的示例:

  

机器人:字体=" @字体/ lobster_regular"

我认为它是你添加到assets / font文件夹的字体。但是,当我尝试它时,我不明白为什么它无法找到我添加的字体。它只有鳍,无衬线和单声道空间。任何人都知道这可能是什么问题?

我知道还有其他方法可以添加自定义字体,但由于我想要使用的材质日历,我需要在样式XML中定义,只能自定义它。我尝试了calligraphy lib,但没有帮助。

2 个答案:

答案 0 :(得分:1)

使用字体轻松设置字体系列

Typeface type = Typeface.createFromAsset(getAssets(),
            "fonts/fontname");

现在将此字体设置为textview

tv.setTypeface(type);

答案 1 :(得分:0)

将此添加到您的活动代码:

TextView tv = (TextView) findViewById(R.id.appname);
Typeface face = Typeface.createFromAsset(getAssets(),
            "fonts/fontname");

tv.setTypeface(face);

请注意,为此,您必须在app/src/main/assets

创建字体文件夹
相关问题