我试图通过遵循
在android应用程序中应用自定义字体https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml教程。
但是我收到“链接文件资源失败” 错误。我在res> font文件夹中有字体jameel_noori.ttf
,字体资源文件jameel.xml
具有android和app命名空间。请帮我我在做什么错了?
我的应用minsdkversion
是17。我必须在片段中使用自定义字体。
这是我的字体资源文件jameel.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- regular -->
<font
android:font="@font/jameel_noori_regular"
android:fontStyle="normal"
android:fontWeight="400"
app:font="@font/jameel_noori_regular"
app:fontStyle="normal"
app:fontWeight="400" />
<!-- italic -->
<font
android:font="@font/jameel_noori_italic"
android:fontStyle="italic"
android:fontWeight="400"
app:font="@font/jameel_noori_italic"
app:fontStyle="italic"
app:fontWeight="400" />
<!-- bold -->
<font
android:font="@font/jameel_noori_bold"
android:fontStyle="normal"
android:fontWeight="700"
app:font="@font/jameel_noori_bold"
app:fontStyle="normal"
app:fontWeight="700" />
片段布局文件fragment_single_dua.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tv_urdu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:lineSpacingExtra="10dp"
android:paddingTop="6dp"
android:text="@string/sample_arabic_text"
android:textAlignment="gravity"
android:textColor="@color/black"
android:textSize="26sp"
android:fontFamily="@font/jameel"/>
</LinearLayout>
这是我正在构建的错误:
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:6: error: attribute font (aka com.alhuda.duasapp.sonayjagnaykayazkaar:font) not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:6: error: attribute fontStyle (aka com.alhuda.duasapp.sonayjagnaykayazkaar:fontStyle) not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:6: error: attribute fontWeight (aka com.alhuda.duasapp.sonayjagnaykayazkaar:fontWeight) not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:6: error: attribute android:font not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:6: error: attribute android:fontStyle not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:6: error: attribute android:fontWeight not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:16: error: attribute font (aka com.alhuda.duasapp.sonayjagnaykayazkaar:font) not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:16: error: attribute fontStyle (aka com.alhuda.duasapp.sonayjagnaykayazkaar:fontStyle) not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:16: error: attribute fontWeight (aka com.alhuda.duasapp.sonayjagnaykayazkaar:fontWeight) not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:16: error: attribute android:font not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:16: error: attribute android:fontStyle not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:16: error: attribute android:fontWeight not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:26: error: attribute font (aka com.alhuda.duasapp.sonayjagnaykayazkaar:font) not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:26: error: attribute fontStyle (aka com.alhuda.duasapp.sonayjagnaykayazkaar:fontStyle) not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:26: error: attribute fontWeight (aka com.alhuda.duasapp.sonayjagnaykayazkaar:fontWeight) not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:26: error: attribute android:font not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:26: error: attribute android:fontStyle not found.
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\font\jameel.xml:26: error: attribute android:fontWeight not found.
error: failed linking file resources.
我在android:fontFamily="@font/jameel"
中尝试过app:fontFamily="@font/jameel"
和Textview
,但错误仍然存在。