从字体资源 id 创建字体 [英] create typeface from font resource id

查看:24
本文介绍了从字体资源 id 创建字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过使用 Typeface.createFromAsset(getAssets(),"font/myfont.ttf"));

我知道字体目录应该在资产中,但就我而言,我有一个现有的字体资源目录,所以我认为资产管理器将从字体资源目录中读取,但我错了.我正在创建字体来为 collapsingToolbarLayout 设置自定义字体.

I know font directory should be in assets but in my case, I have an existing font resource directory so I thought asset manager will read from font resource directory but I was wrong. I am creating Typeface to set custom font for collapsingToolbarLayout.

我找到了这个答案 但它需要我在资产中保留字体

I found this answer but it requires me to keep font in assets

推荐答案

这行得通

Typeface typeface = ResourcesCompat.getFont(this, R.font.app_font);

在@Eselfar 的教程链接中找到了这个

Found this in the tutorial link by @Eselfar

这篇关于从字体资源 id 创建字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆