I'm trying to create a dark theme similar to the one in OxygenOS on OnePlus devices.
I changed the window background to black but the problem is the action bar is not becoming pure black.
<style name="DarkTheme" parent="Theme.AppCompact">
<item name="android:colorPrimary">@color/black</item>
<item name="android:colorPrimaryDark">@color/black</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:colorAccent">@color/white</item>
<item name="android:color">@color/white</item>
<item name="android:windowBackground">@color/black</item>
<item name="android:navigationBarColor">@color/black</item>
<item name="android:actionBarStyle">@color/black</item>
</style>
This year at I/O 2019 Google announced that Android will now support Dark Theme at OS level. At the same time we’re seeing more Google apps being rolled out with dark UI support. This will become soon a common pattern and other apps will follow on this path.
Gboard also offers theme support, with one of these themes being a proper black theme. And with keyboards being a fixture in almost every app, this is definitely one of the first dark mode apps you should grab. This app has long been a fixture on Android smartphones, and for very good reason.
The dark theme for Kindle only changes the layout of the app UI. If you want to read the books in the dark mode then you can simply change the background to black. It helps the eyes during night time and saves battery.
Note that dark-themed android:windowBackground drawables only work on Android 10. When the app’s theme changes (either through the system setting or AppCompat) it triggers a uiMode configuration change. This means that Activities will be automatically recreated.
SIMPLEST SOLUTION
You can enable/disable dark theme just by:
enable dark theme:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
forcefully disable dark theme:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
set app theme based on mobile settings of dark mode, i.e. if dark mode is enabled then the theme will be set to a dark theme, if not then the default theme, but this will only work in version >= Android version Q
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
Notes:
"Theme.AppCompat.DayNight"
like
<style name="DarkTheme" parent="Theme.AppCompat.DayNight">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
drawable & drawable-night,
values & values-night
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