我正在Android片段中的textview上应用自定义字体。字体显示在布局设计预览中,而不显示在实际设备上。字体.ttf位于res> font文件夹中。
字体资源文件为jameel.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">
<!-- regular -->
<font
android:font="@font/jameel_noori"
android:fontStyle="normal"
android:fontWeight="400"
app:font="@font/jameel_noori"
app:fontStyle="normal"
app:fontWeight="400" />
<!-- italic -->
</font-family>
片段布局中的Textview:
<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"/>
如果我将android:fontFamily="@font/jameel"
更改为app:fontFamily="@font/jameel"
,则构建失败并显示以下错误:
C:\Users\Zoha\StudioProjects\SonayJagnayKayAzkaar1\app\src\main\res\layout\fragment_single_dua.xml:88: error: attribute fontFamily (aka com.alhuda.duasapp.sonayjagnaykayazkaar:fontFamily) not found.
error: failed linking file resources.
我的build.gradle是:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.alhuda.duasapp.sonayjagnaykayazkaar"
minSdkVersion 17
targetSdkVersion 27
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
implementation 'com.android.support:support-v4:27.0.2'
}