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

时间:2019-11-04 13:24:57

标签: android fonts

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

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

我已经遵循了一些教程,但是我做到了:

  1. 在res中创建了名为font的文件夹

  2. 将我的ttf字体文件复制粘贴到其中

  3. 创建的字体资源文件

    • 这是问题所在-字体家族XML中引用ttf

图片: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>

1 个答案:

答案 0 :(得分:0)

对我来说,更简单的解决方法是打开我的layout.xml并在属性中选择字体系列。这样,您可以安装Google字体,该字体会自动在/res中创建字体文件夹。

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