错误:找不到与给定名称匹配的资源:'typeface'属性

5
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="TextViewAppearance" parent="@android:style/TextAppearance.Widget.TextView">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="typeface">robotoRegular</item>            
    </style>

    <style name="TextViewAppearance.Display1" parent="@style/TextViewAppearance">
        <item name="typeface">robotoBlack</item>
        <item name="android:textSize">45sp</item>
        <item name="android:textColor">@color/main_color_grey_500</item>
    </style>
</resources>

出现错误: Error:(4, 5)未找到与给定名称匹配的资源:属性'typeface'。

我在使用:
1. Android Studio 1.5.1
2. minSdkVersion 15
3. targetSdkVersion 23

<----------- 编辑 --------------------->

我的布局文件为

<abcapp.com.font.RobotoTextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"               
                android:text="ABC"               
                android:textSize="16sp"
                app:typeface="robotoBlack" />
3个回答

8

字体类(Typeface class)指定了字体的字体类型和内置样式。

应该调用 android:typeface 而不是 typeface

不要

<item name="typeface">robotoRegular</item>

<item name="android:typeface">robotoRegular</item>

我正在xml布局文件中使用“app:typeface”。我刚刚在我的问题中添加了xml布局文件代码。 - Ali
1
@smoke https://dev59.com/B3A85IYBdhLWcg3wCe9Z - IntelliJ Amiya

1
你应该使用 android:typeface,而不是 typeface

我正在xml布局文件中使用“app:typeface”。我刚刚在我的问题中添加了xml布局文件代码。 - Ali
但是看起来你没有像android那样声明app标签。 - starkshang

0

使用

<item name="android:typeface">YOUR FONT</item>

我正在xml布局文件中使用“app:typeface”。我刚刚在我的问题中添加了xml布局文件代码。 - Ali

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接