无法添加自定义字体,找不到@font/fontname.ttf

Can't add custom fonts, @font/fontname.ttf is not found

我无法在属性中添加我的字体文件:

android:font="@font/Roboto-Regular"

我已经学习了一些教程并且我做到了:

  1. 在 res

  2. 中创建了名为 font 的文件夹
  3. 复制粘贴我的ttf字体文件到里面

  4. 已创建字体资源文件

    • 问题出在这里 - 在字体系列中引用 ttf XML

图片:https://imgur.com/ZDGG1Mo

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">


    <font
        android:font="@font/Roboto-Regular"
        android:fontStyle="normal"
        android:fontWeight="400"
        app:font="@font/Roboto-Regular"
        app:fontStyle="normal"
        app:fontWeight="400"
        tools:ignore="UnusedAttribute" />

</font-family>

对我来说,更简单的解决方案是打开我的 layout.xml 并在属性中打开 select 字体系列。这样你就可以安装 Google 字体,它将自动在 /res.

中创建字体文件夹

此外,我相信它的 android:fontFamily="@font/Roboto-Regular" 语法。