switch dark mode like whatsapp/slack etc

138 views Asked by At

I know switching dark mode on android programmatically is easy with below code.

    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)

I want to know how to do it like whatsapp/slack which won't restart the app. User will still be in preferences fragment and mode changes there right away. If I try above line, my activity is recreated and first fragment is launched but not preference fragment.

How to handle it the way they are handling it?

1

There are 1 answers

0
Phantom Lord On

Put in the manifest android:configChanges="...|uiMode|..." for that activity and use a day/night theme, doing so, the switch is automatic and with 0 lines of code