Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70764

Dark Mode Theme

$
0
0

@Jignesh2810 wrote:

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 used the android system by default dark mode get but not getting.

    // 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

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70764

Trending Articles



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