I want to implement android 10 dark theme in my app , I have these following cases:
SYSTEM_DEFAULT, NIGHT_MODE, LIGHT_MODE
The problem is when I
You don't need to set the theme in your activity and recreate it. It's done automatically if you've setup your app theme right.
To use the Dark in your app, you should extend the DayNight theme as your app theme.
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
or
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
If you want for example a different color during dark mode, you should create a 'Android resource directory' called values-night with a 'resource file called colors.xml
In the colors.xml you can set a different color hex for one of your existing colors.
For example:
values/colors.xml contains
<color name="myColor">#000000</color>
values-night/colors.xml contains
<color name="myColor">#FFFFFF</color>
EDIT
You can switch between Dark/light mode in app by calling
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
or
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
or
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)