Reputation: 873
In my app, I've tried to change theme (light/dark) with uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_YES)
.
It works perfectly on my Nexus 5 with Android 6 and on an emulator with Android 6, but it doesn't work on emulator with Android 5.1.
Why?
I've also tried with AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
but on Android 6 it change only the menu theme (?) and on Android 5 doesn't work anyway..
I don't think that is a problem of theme, but this is my code:
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style>
Upvotes: 1
Views: 1252
Reputation: 29260
Use
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
in your Application's onCreate method.
Upvotes: 3