Android错误(使用对话框时无法从可绘制资源中找到ColorStateList)

【Android错误(使用对话框时无法从可绘制资源中找到ColorStateList)】黄沙百战穿金甲,不破楼兰终不还。这篇文章主要讲述Android错误:使用对话框时无法从可绘制资源中找到ColorStateList相关的知识,希望能为你提供帮助。
我正在尝试对新的android材料库进行测试,但经过数小时的调查后,我无法弄清楚如何解决这个问题。
当我尝试打开任何类型的对话框时发生错误。
这是错误

android.content.res.Resources $ NotFoundException:无法在android.content.res.Resources.loadColorStateList(android.content.res.Resources.loadColorStateList)的android.content.res.ResourcesImpl.loadColorStateList(ResourcesImpl.java:1042)中找到可绘制资源ID#0x7f070018的ColorStateList .java:1041)在com.android.internal.policy的com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2436)的android.content.res.TypedArray.getColor(TypedArray.java:469)。 PhoneWindow.installDecor(PhoneWindow.java:2672)at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:410)at com.android.internal.app.AlertController.installContent(AlertController.java:263)at android Android.app.Dialog.show上的android.app.Dialog.dispatchOnCreate(Dialog.java:407)中的.app.AlertDialog.onCreate(AlertDialog.java:436)(Dialog.java:302)
ID为#0x7f070018的资源解析为abc_dialog_material_background,它是appcompat库的一部分。
这是调用错误的代码
val c = Calendar.getInstance() val year = c.get(Calendar.YEAR) val month = c.get(Calendar.MONTH) val day = c.get(Calendar.DAY_OF_MONTH)DatePickerDialog(requireContext(), DatePickerDialog.OnDateSetListener { _, y, m, dayOfMonth -> println(y) println(m) println(dayOfMonth) }, year, month, day).show()

这是我的模块build.gradle文件
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply plugin: 'androidx.navigation.safeargs'android { compileSdkVersion rootProject.compileSdkVersion buildToolsVersion '28.0.2'dataBinding { enabled = true }defaultConfig { applicationId 'moe.anekoisfinetoo.peek' minSdkVersion rootProject.minSdkVersion targetSdkVersion rootProject.targetSdkVersion versionCode 1000 versionName '0.1.0' testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' }buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }dependencies { /* Any jar files */ implementation fileTree(dir: 'libs', include: ['*.jar'])/* Android Constraint Layout * https://developer.android.com/training/constraint-layout/index.html */ implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion"/* Android KTX * https://developer.android.com/kotlin/ktx */ implementation "androidx.core:core-ktx:$rootProject.ktxVersion"/* Android Lifecycle Libraries * https://developer.android.com/topic/libraries/architecture/lifecycle */ implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.lifecycleExtensionsVersion"/* Android Material Components * https://github.com/material-components/material-components-android */ implementation "com.google.android.material:material:$rootProject.materialVersion"/* Android Navigation * https://developer.android.com/topic/libraries/architecture/navigation */ implementation "android.arch.navigation:navigation-fragment-ktx:$rootProject.navigationVersion" implementation "android.arch.navigation:navigation-ui-ktx:$rootProject.navigationVersion" androidTestImplementation "android.arch.navigation:navigation-testing-ktx:$rootProject.navigationVersion"/* Android Support Libraries * https://developer.android.com/topic/libraries/support-library/index.html */ implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"/* Kotlin * https://kotlinlang.org/ */ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$rootProject.kotlinVersion"/* Material Dialogs * https://github.com/afollestad/material-dialogs */ implementation "com.afollestad.material-dialogs:core:$rootProject.materialDialogs"/* Testing */ testImplementation "junit:junit:$rootProject.junitVersion" androidTestImplementation "androidx.test:runner:$rootProject.runnerVersion" androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.espressoCoreVersion" }

所有版本都从项目build.gradle中检索并且是最新的。
答案在一个新项目中一步一步地再做一切后发现问题,它是应用程序主题中的一个项目。
< item name="android:statusBarColor"> ?android:attr/windowBackground< /item>

删除该行或将值更改为colors.xml中定义的颜色后,对话框开始重新运行。因为我希望状态栏与背景颜色相同,所以我只是为此改变它,得到相同的结果和工作对话框。
< item name="android:statusBarColor"> ?android:attr/colorBackground< /item>


    推荐阅读