首页 > 解决方案 > Android Studio 3.1.4 设计预览不渲染材料设计元素

问题描述

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

java.lang.IllegalArgumentException:restoreToCount 中的下溢 - 在 android.support.design.widget.CutoutDrawable.postDraw(CutoutDrawable.java:113) 在 android.graphics.Canvas.restoreToCount(Canvas.java:604) 在 android .support.design.widget.CutoutDrawable.draw(CutoutDrawable.java:87) 在 android.support.design.widget.TextInputLayout.draw(TextInputLayout.java:1575)

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

材料设计元素渲染不当

我一直在寻找解决此问题的方法,但似乎找不到任何对当前版本的 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'`

候选发布库之一是否可能存在问题?

标签: androidandroid-studioandroid-9.0-pieandroid-studio-3.1.4

解决方案


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

implementation 'com.android.support:appcompat-v7:28.0.0-rc01'( rc01 )

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'( alpha1 )

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


推荐阅读