androidandroid-10.0android-dark-themeandroid-darkmode

Android - Detect if the user's OS theme is dark or light?


I need to know if user has enabled dark theme in the OS level so that I can enable dark theme in my app automatically.(not force dark mode)


Solution

  • To detect if the system is in dark theme. Helpful.

    switch (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
        case Configuration.UI_MODE_NIGHT_YES:
           //process
            break;
        case Configuration.UI_MODE_NIGHT_NO:
            // process
            break; 
    }