Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable android:forceDarkMode programmatically?

Android Q introduced a setting to force dark mode on apps without worrying about changing the colors manually: https://developer.android.com/preview/features/darktheme#force_dark

This works fine even for my app which uses a WebView! However, I would like to give users the choice to enable dark mode whenever they need it. Is it possible to leverage the automatic changes done by "android:forceDarkAllowed" for that purpose?

like image 985
TomTasche Avatar asked Jun 16 '19 09:06

TomTasche


1 Answers

You can programmatically enable the dark theme on Android Q with the following code: AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

like image 160
TomTasche Avatar answered Sep 29 '22 00:09

TomTasche