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?
Turn Dark theme on or off in your phone's settings Important: When you turn on Dark theme for your phone, many apps also use Dark theme. On your phone, open the Settings app. Tap Display. Turn Dark theme on or off.
Take a look at the colors defined in the default theme. In Android Studio, open themes. xml (app > res > values > themes > themes. xml).
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.
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