Benutzerdefinierte Schriftarten mit Unterstützung der Bibliothek funktioniert nicht auf einem realen Gerät

Habe ich verwendet benutzerdefinierte schriftart mit Unterstützung der Bibliotheks-API-26. Erstellt habe ich font-family mit style, und fügen Sie Stil, um meinen text anzeigen. Ich fand, dass die schriftart einstellen, in der Vorschau im design, aber funktioniert nicht in android auf echten Geräten. Unten ist mein code und ich habe auch angehängten screenshot. Vielen Dank im Voraus.

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:

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

bauen.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'

Font resource dir:

Benutzerdefinierte Schriftarten mit Unterstützung der Bibliothek funktioniert nicht auf einem realen Gerät

Design-Vorschau: Hier schriftart arbeitet

Benutzerdefinierte Schriftarten mit Unterstützung der Bibliothek funktioniert nicht auf einem realen Gerät

Android-Gerät Screenshot: Hier schriftart funktioniert nicht

Benutzerdefinierte Schriftarten mit Unterstützung der Bibliothek funktioniert nicht auf einem realen Gerät

  • haben Sie das Format anwenden, um Ihre textview? Überprüfen Sie die xml -
  • Ich sehe das gleiche problem. Ich versuchte, Sie verweisen auf die Schrift direkt (statt über eine schriftart-Familie), und auch versucht, sowohl die otf-und ttf-Dateien. Es funktioniert in Android Studio in der Vorschau, aber nicht auf eine API-24-Gerät.
  • was für mich funktioniert: segunfamisa.com/posts/custom-fonts-with-android-support-library
  • hast du eine Lösung ?
Schreibe einen Kommentar