Im trying to use android dark theme. I install android studio 3.5 preview.
compileSdkVersion 28 targetSdkVersion 28
but still getting this error. Is this dark theme bug or Im doing something wrong?
build.gradle{
dependencies {
    // ...
    implementation 'com.google.android.material:material:1.1.0-alpha06'
    // ...
  }}
styles.xml
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
    <item name="android:forceDarkAllowed">true</item>
</style>
project link
https://github.com/googlesamples/android-DarkTheme
You need to up your compiledSdkVersion to 29, in you app build.gradle:
android {
    compileSdkVersion 29
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        ...
}
Then you should be good to go!
I was searching for an answer and as @Ruben pointed out)
Changing
compiledSdkVersion28 tocompileSdkVersion'android-Q'should solve the issue.android:forceDarkAllowedattribute was only added inAndroid Q.Unrelated to this issue, but it seems like you need to also update
'androidx.appcompat:appcompat:1.1.0-alpha04'to'androidx.appcompat:appcompat:1.1.0-alpha05'or the theme switching doesn't work properly.
I encountered the same error message when I tried to run my previously untouched Angular based NativeScript "Hello World" android application. (In command prompt: tns create, tns run android --bundle)
For me the solution was: 1. Open SDK Manager in Android Studio 2. Install Android 10.0 (Q) (API Level: 29) SDK Platform.
After these steps I could start running my app without any errors!
I found the answer in android studio suggestions. for clarification the tag android:forceDarkAllowed is only found in api level 29+ so what we should do is create a folder values-v29 and then write the tag in it like below
in file values/____.xml
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
    //removed from here
</style>
in file values-v29/____.xml
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
    <item name="android:forceDarkAllowed">true</item>
</style>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With