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

5.9k Views Asked by At

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)

1

There are 1 best solutions below

2
On BEST ANSWER

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; 
}