Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230059

Dark Mode not working for ionic 5

$
0
0

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

AppComponent

initializeApp() {
    this.platform.ready().then(() => {
      this.displayMode.toggleDisplayMode();
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }

but it’s not on the Android device, even after i have added the class='dark' explicitly.
I think there is some some tips before we push the project. :grin:


Viewing all articles
Browse latest Browse all 230059

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>