【问题标题】:How to change font from a kotlin project? [duplicate]如何从 kotlin 项目更改字体? [复制]
【发布时间】:2020-05-27 22:54:18
【问题描述】:

我正在尝试从 MainActivity 中的特定 EditText 更改字体,但出现以下错误:

java.lang.RuntimeException: 未找到字体资源 font/af.ttf

代码:

val texto: EditText = findViewById(R.id.texto)
        var face = Typeface.createFromAsset(assets, "font/af.ttf")
        texto.typeface = face

我该如何解决这个问题?

【问题讨论】:

标签: android kotlin


【解决方案1】:

你应该把你的字体移动到 assets 目录

来自文档

   /**
     * @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)

【讨论】:

  • 我没有资产文件夹
  • 您可以通过右键单击主包然后新建/目录来创建
  • 成功了,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-20
  • 2013-06-29
  • 2019-11-23
  • 1970-01-01
  • 2019-11-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多