gpt4 book ai didi

android - 带有支持库的自定义字体在真实设备上不起作用

转载 作者:IT老高 更新时间:2023-10-28 23:38:43 25 4
gpt4 key购买 nike

我在 Support Library API 26 中使用了自定义字体。我使用样式创建了字体系列并将样式添加到我的 TextView 中。我发现字体会在设计期间在 Preview 中设置,但在 android 真实设备中不起作用。下面是我的代码,我还附上了截图。提前致谢。

TextView :

<TextView
android:id="@+id/card_number_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="111 5235 5563 8845"
android:gravity="left"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="8dp"
style="@style/creditCardText"
app:layout_constraintTop_toBottomOf="@+id/payableLayout"
app:layout_constraintLeft_toLeftOf="@+id/payableLayout"
app:layout_constraintHorizontal_bias="0.0" />

Style.xml:

<style name="creditCardText">
<item name="android:textSize">@dimen/textSizeLarge</item>
<item name="android:fontFamily">@font/font_roboto_medium</item>
<item name="android:textColor">@color/color_card_number</item>
</style>

字体系列:

<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/roboto_medium" />

build.gradle:

apply plugin: 'com.android.application'
buildscript {
repositories {
}
dependencies {
}
}

android {
signingConfigs {
}
compileSdkVersion 26
defaultConfig {
applicationId "org.saifintex.skypaytrans"
minSdkVersion 18
targetSdkVersion 26
vectorDrawables.useSupportLibrary = true
versionCode 7
multiDexEnabled true
versionName "1.6"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}

lintOptions {
abortOnError false // true by default
checkAllWarnings false
checkReleaseBuilds false
ignoreWarnings true // false by default
quiet true // false by default
}

repositories {
maven { url "https://jitpack.io" }
}
dexOptions {
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
productFlavors {
}
sourceSets {
main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
java.srcDirs = ['src/main/java', 'src/main/java/fonts']
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "com.android.support:appcompat-v7:26.1.0"
compile "com.android.support:design:26.1.0"
compile "com.android.support:recyclerview-v7:26.1.0"
compile project(':tooltip')
compile project(':mylibrary')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.j256.ormlite:ormlite-
android:${rootProject.ormliteAndroidVersion}"
compile "com.j256.ormlite:ormlite-core:${rootProject.ormliteCoreVersion}"
testCompile 'junit:junit:4.12'
compile 'com.afollestad.material-dialogs:core:0.9.4.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.android.volley:volley:1.0.0'
compile 'commons-codec:commons-codec:1.10'
compile 'com.android.support:design:26.1.0'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.wang.avi:library:2.1.3'
compile 'com.github.ayalma:ExpandableRecyclerView:0.2.0'
compile 'com.github.deano2390:MaterialShowcaseView:1.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-crash:11.0.1'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.android.gms:play-services-analytics:11.0.1'
compile 'com.alimuzaffar.lib:pinentryedittext:1.3.1'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'
testCompile 'junit:junit:4.12'
}

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex") &&
!requested.name.startsWith("crash")) {
details.useVersion '25.3.1'
}
}
}
}

apply plugin: 'com.google.gms.google-services'

字体资源目录:

enter image description here

设计预览:这里的字体正在工作

enter image description here

Android 设备屏幕截图:这里的字体不起作用

enter image description here

最佳答案

将您的 TextView 更改为 android.support.v7.widget.AppCompatTextView。

https://stackoverflow.com/a/45208134/332798

关于android - 带有支持库的自定义字体在真实设备上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47262998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com