我正在尝试使用Font作为XML中的资源,而不是使用Typeface。
我在/res/font directory中保存了.ttf文件。
我已经实现了类似这样的东西
在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').`谢谢。
发布于 2017-11-08 00:32:21
将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.zipxml文件
<?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>确保这是正确的,它应该出现在字体文件夹中,并重建项目(无效缓存/重新启动)
发布于 2017-10-31 18:18:01
您可以从更改字体位置
res/font directory至
\assets\fonts它对我很有效,我希望它能帮助你解决问题
发布于 2017-10-31 18:18:36
您正在制作资源内的字体文件夹, .It是错误的。
您必须在asset中创建字体文件夹
请按照以下步骤操作。
Right Click on app > New > Folder > Assets Folder

https://stackoverflow.com/questions/47032803
复制相似问题