Hii,
I have tried below code to apply “Dark Mode” theme but is not working in ionic 3 and 4 also try in ionic 1 but the same result.
-
I tried the android system setting to select dark mode but when tried to below code result is false.
// Use matchMedia to check the user preference
const prefersDark = window.matchMedia(’(prefers-color-scheme: dark)’);toggleDarkTheme(prefersDark.matches);
// Listen for changes to the prefers-color-scheme media query
prefersDark.addListener((mediaQuery) => toggleDarkTheme(mediaQuery.matches));// Add or remove the “dark” class based on if the media query matches
function toggleDarkTheme(shouldAdd) {
document.body.classList.toggle(‘dark’, shouldAdd);
} -
In the above code, "const prefersDark " value always returns a false value
Please tell me anything wrong on my side.
Thanks you