好吧,我正在尝试将 textview 字体系列更改为自定义字体 我用了this documentation from Google
但是我的应用程序在启动时崩溃了这就是我所做的
我创建了一个 Android 资源目录并向其中添加了我的字体(使用 Windows 资源管理器) Here is a screenshot of that directory
然后我在该目录中创建了一个名为 myfont 的 Android 资源文件,这里是它的内容:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/droidkufi_regular" />
</font-family>
Ps:字体文件名是droidkufi_regular.ttf(本来是大写的,我改成小写了)
这是我的 TextView
<TextView
.
.
android:fontFamily="@font/myfont"
.
.
/>
我运行该应用程序,在 gradle 构建中一切看起来都不错,但是当该应用程序在我的手机上启动时它崩溃了(“应用程序名称”已停止)我还尝试重新启动我的手机,清除应用程序数据,重新安装,然后安装模拟器上的应用程序。
这里是 logcat: 在 pastebin 因为它有点长 (包名是 com.mypackagename) https://pastebin.com/cjh67DZm
注意:这只发生在自定义字体上,当我使用这样的系统字体时: android:fontFamily="草书" 它按预期工作。
最佳答案
同时使用:
android:font="@font/yourFont"
和:
app:font="@font/yourfont"
关于android - 为 textview 提供 Resources$NotFoundException 的自定义 fontFamily,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48172107/