How can I provide you the project?
I just followed the tutorial on the website to create a project and afterwards I tried to implement the dark mode like described in the dark mode tutorial.
If I change another value in the variables.scss like the primary color the changes are applied to the app.
Hi @mhartington
I have the same issue, the Dark mode works fine in desktop browser by using the below code
export class DisplayModeService {
constructor() { }
toggleDisplayMode() {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
prefersDark.addEventListener('change', (mediaQuery) => this.toggleDarkTheme(mediaQuery.matches));
this.toggleDarkTheme(prefersDark.matches);
}
// Add or remove the "dark" class based on if the media query matches
private toggleDarkTheme(shouldAdd) {
document.body.classList.toggle('dark', shouldAdd);
}
}
@mhartington The dark mode works only when I change my display mode setting in Windows, also it’s not working on Android even if I set the settings to DarkTheme.
Ahh, so the example you have doesn’t do anything with the dark class you add to the body.
It relies on the @media (prefers-color-scheme: dark) setting only.
If you want both, you need to listen for the media query and the class list.
@mhartington this is very confusing that the docs show to just add the dark class, but doesn’t mention that the media query comes standard, but you need to add the class to the css. Both should be included in the starter projects.
Most android devices do not support dark mode at the moment. You’ll need to check your android version and see if it support system wide dark mode settings first.
Hey, thanks a lot for your support but i have searched the web and darkmode is not affecting my ionic android app , when i turn on darkmode on IOS it affects the prefers-color-scheme.
Is there any solution to allow prefers-color-scheme:dark work on android apps.