AAPT:错误:找不到属性android:forceDarkAllowed

ksg*_*rkn 8 android android-theme android-styles

我试图使用android黑暗主题。我安装了android studio 3.5预览版。

compileSdkVersion 28目标SdkVersion 28

但仍然出现此错误。这是黑暗主题错误还是我做错了什么?

build.gradle{
dependencies {
    // ...
    implementation 'com.google.android.material:material:1.1.0-alpha06'
    // ...
  }}
Run Code Online (Sandbox Code Playgroud)

styles.xml

<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
    <item name="android:forceDarkAllowed">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

项目链接

https://github.com/googlesamples/android-DarkTheme

svk*_*aka 5

我正在寻找答案,正如@Ruben指出的

compiledSdkVersion 28更改为compileSdkVersion 'android-Q'应该可以解决该问题。android:forceDarkAllowed属性仅添加到中 Android Q

与此问题无关,但似乎您还需要更新 'androidx.appcompat:appcompat:1.1.0-alpha04'至, 'androidx.appcompat:appcompat:1.1.0-alpha05'否则主题切换无法正常工作。


Tas*_*iwa 5

您需要compiledSdkVersion在应用程序build.gradle中将其增加到29个:

android {
    compileSdkVersion 29
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        ...
}
Run Code Online (Sandbox Code Playgroud)

那你应该很好走!