Class DarkModeDetector


  • public final class DarkModeDetector
    extends java.lang.Object
    A "dark mode" detector for common platforms. Modern desktops often support selecting a dark theme that inverts the typical dark-text-on-light-background form. This class can detect whether such a style is active on a number of common platforms. If it cannot definitively establish that dark mode is active, it will report that it is not active.
    Since:
    3.2
    Author:
    Chris Jennings
    • Constructor Summary

      Constructors 
      Constructor Description
      DarkModeDetector()
      Creates a new detector instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean detect()
      Detects whether dark mode is active.
      boolean isDetected()
      Returns the result of the most recent detection.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DarkModeDetector

        public DarkModeDetector()
        Creates a new detector instance. The value of isDetected() is not accurate until detect() has been called.
    • Method Detail

      • detect

        public boolean detect()
        Detects whether dark mode is active.
        Returns:
        true if dark mode was detected, false if dark mode could not be detected
      • isDetected

        public boolean isDetected()
        Returns the result of the most recent detection. If no detection has been performed, returns false.
        Returns:
        true if dark mode was detected after the most recent call to detect().