【问题标题】:Font in XML using Support Library 26.1: Rendering Issues使用支持库 26.1 的 XML 字体:呈现问题
【发布时间】:2018-04-03 16:39:10
【问题描述】:

我决定使用Fonts in XML 功能在我的应用程序中使用一种自定义字体。我确保完成以下操作:

  • 使用支持库 26.1.0(因为我的目标是 API 级别 19 及以上)
  • Gradle 文件已同步
  • 字体直接添加到 XML 中,而不是通过编程方式
  • 按照链接中提供的相应说明进行操作

一切正常,当我在虚拟设备中运行我的应用程序时,我可以看到 Buttons 上使用的自定义字体。

但是,在 XML 中应用自定义字体后,弹出两个警告:

  • 布局保真度警告
  • 无法实例化一个或多个类

如何消除这些警告?如果我不能,他们可以安全地忽略吗?


应用的 Gradle 文件(部分):

apply plugin: 'com.android.application'

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    compile "com.android.support:support-compat:26.1.0"
}

XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ks.shakee.MainMenuActivity">

    <LinearLayout
        android:id="@+id/ll_mainmenu"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="64dp"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:divider="@drawable/divider_vertical_invisible_medium"
        android:orientation="vertical"
        android:showDividers="middle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <Button
            android:id="@+id/btn_timedgame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/myfont"
            android:text="Timed Challenge"
            android:textSize="32dp" />

        <Button
            android:id="@+id/btn_bestscore"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/myfont"
            android:text="Best Score"
            android:textSize="32dp"
            tools:layout_editor_absoluteX="66dp"
            tools:layout_editor_absoluteY="231dp" />
    </LinearLayout>

</android.support.constraint.ConstraintLayout>

【问题讨论】:

    标签: android android-support-library android-xml


    【解决方案1】:

    今天刚刚将我的 Android Studio 更新为 3.1,并将我的 Gradle 文件改为使用 27.1。警告消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-17
      • 2011-04-14
      • 2015-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多