Android Studio 3.1.4 设计预览不渲染 Material Design 元素

标签 android android-studio android-9.0-pie android-studio-3.1.4

我使用的是 Android Studio 3.1.4。为了使用最新的 Material 设计库,我将编译和目标 SDK 版本更新为 28。现在,我在基本线性布局中使用一些 TextInputLayouts 和 TextInputEditTexts,设计预览无法正确渲染它们。它也不会渲染正确跟随它的任何元素。我在设计预览中遇到以下错误:

java.lang.IllegalArgumentException: Underflow in restoreToCount - more restores than saves at android.graphics.Canvas.restoreToCount(Canvas.java:604) at android.support.design.widget.CutoutDrawable.postDraw(CutoutDrawable.java:113) at android.support.design.widget.CutoutDrawable.draw(CutoutDrawable.java:87) at android.support.design.widget.TextInputLayout.draw(TextInputLayout.java:1575)

预览实际上是这样的 - 对设计没有特别帮助:

Improper Rendering of Material Design Elements

我一直在寻找解决方案,但似乎找不到任何对当前版本的 Android Studio 或 SDK 28 有用的内容。这是应用程序 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.the.appname.here"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
    implementation 'com.android.support:exifinterface:28.0.0-rc01'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-v4:28.0.0-rc01'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:28.0.0-rc01'
    implementation 'com.android.support:cardview-v7:28.0.0-rc01'
    implementation 'com.android.support:design:28.0.0-rc01'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.3'
    implementation ('com.twitter.sdk.android:twitter:3.3.0@aar') {
        transitive = true
    }
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}

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

候选版本库之一是否可能存在问题?

最佳答案

为了完成这项工作,我改变了:

实现“com.android.support:appcompat-v7:28.0.0-rc01” (rc01)

实现“com.android.support:appcompat-v7:28.0.0-alpha1” (alpha1)

我在网上看到了这个,并且根据我的测试它正在工作,唯一的缺点是您必须在每个项目上进行此更改。

关于Android Studio 3.1.4 设计预览不渲染 Material Design 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51942672/

相关文章:

android - 加速 Android 应用程序构建 - Java 编译器使用多个 CPU 内核

java - EditText 到 String 到 double 转换及计算错误

android - 在 Android Studio 中进行 gradle 构建时,如何将资源提取到资源目录中?

android - 何时使用 PreferenceFragment 和 PreferenceFragmentCompat?

android - 带有 io.pristine :libjingle 的 webrtc android

Android Matrix.multiplyMV 没有通过翻译改变我的结果

Java/Android工作室: For loop - Same data shows multiple times

Android WebView 已开始在 Android 9 上崩溃

java - 如何构建AOSP来获取jar文件?

java - 如何在更新后第一次打开应用程序时仅启动一次 Activity ?