【问题标题】:Using Fonts in a resource file在资源文件中使用字体
【发布时间】:2020-04-14 15:47:14
【问题描述】:

当我为 TextView 使用自定义字体时,我会这样做:

textView.typeface = resources.getFont(R.font.dancing_script)

R.font.dancing_script 引用了我项目的res/font 文件夹中的dancing_script.tff 文件。

现在,Android Studio 告诉我对getFont() 的调用需要minSdkVersion26。 有minSdkVersion < 26的项目应该怎么办?

【问题讨论】:

    标签: android fonts textview android-fonts


    【解决方案1】:

    字体基本上支持两种方式。

    第一

    通过 assets 文件夹,在此您将字体与 apk 打包,因此会增加 apk 大小。

    第二

    通过资源文件夹,在此添加字体 XML 文件,该文件会在安装后下载字体,因此不会增加应用程序的下载大小。 从 android 26 开始支持可下载字体,对于旧版本的支持,您需要使用支持库。 阅读下面的链接 https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多