我正在尝试使用Font作为XML中的资源而不是使用 字体。
我在.ttf
中保留了/res/font directory
个文件。
我已经实现了类似的东西
在Layout XML
<Button android:fontFamily="@font/my_font"/>
在res / font / font.ttf
中<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="40"
android:font="@font/my_font" />
</font-family>
但我仍然得到如下错误。
Error:(156, 33) No resource found that matches the given name (at 'fontFamily' with value '@font/font').`
感谢。
答案 0 :(得分:0)
将您的gradle版本升级到4.1
通过编辑 gradle-wrapper.properties
来完成此操作distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
xml文件
<?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">
<font
android:fontStyle="normal"
app:font="@font/rupee" //this line for below android 26 devices
android:font="@font/rupee" />
</font-family>
确保这是正确的,它应该出现在font文件夹中并重建项目(使缓存/重启无效)
答案 1 :(得分:-1)
您可以从
更改字体位置res/font directory
到
\assets\fonts
它对我有用,我希望它可以帮助你解决问题
答案 2 :(得分:-1)