gpt4 book ai didi

java - Android:找不到 setTextTypeFace 字体资源

转载 作者:行者123 更新时间:2023-12-02 01:07:16 24 4
gpt4 key购买 nike

尝试以编程方式设置字体。

我的文件位于 src/main/res/fonts/material_font.ttf

circleProgress.setTextTypeface(Typeface.createFromAsset(assets, "material_font.ttf" ))

我已经尝试过了

circleProgress.setTextTypeface(Typeface.createFromAsset(assets, "fonts/material_font.ttf" ))
circleProgress.setTextTypeface(Typeface.createFromAsset(assets, "font/material_font.ttf" ))
circleProgress.setTextTypeface(Typeface.createFromAsset(applicationContext.assets, "fonts/material_font.ttf" ))
...

错误是:

Font asset not found MaterialIcons-Regular.ttf

我到底做错了什么?

最佳答案

我们看一下源代码和文档,对于Type.createFromAsset

     /**
* Create a new typeface from the specified font data.
*
* @param mgr The application's asset manager
* @param path The file name of the font data in the assets directory
* @return The new typeface.
*/
public static Typeface createFromAsset(AssetManager mgr, String path)

所以你应该将font.ttf放在资源文件路径中

关于java - Android:找不到 setTextTypeFace 字体资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59851374/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com