Implement change black/light theme feature in Android app

android

Solution

Make sure you call `setTheme()` in `onCreate()` BEFORE calling `setContentView()`. Then if you want to dynamically change the theme again later, you should simply restart your activity.

Problem

I want to have a "change theme" feature in my app. If I call setTheme() in onCreate(), there is one problem. The moment after I launch my app, a plain white background appears for a second (because I have set light theme in the manifest). After that, the complete layout of my Activity is displayed - it is either with white or black background, according to user's theme preference. Is there any way I can change whether white or black background appears after launch?

Original source