Class DynamicColors

java.lang.Object
com.codename1.ui.plaf.DynamicColors

public final class DynamicColors extends Object

The system's dynamic color palette: Material You on Android 12 and newer, the accent color on platforms that have one. On every other platform the methods answer null or the fallback, so an application can keep its own brand colors there.

The palette is a list of RGB values without alpha, indexed by the constants of this class.

int accent = DynamicColors.getColor(DynamicColors.ACCENT, 0x3f51b5);
Label title = new Label("Hello");
title.getAllStyles().setFgColor(accent);
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The primary accent color.
    static final int
    A light tone of the accent, for containers.
    static final int
    The number of palette entries.
    static final int
    A dark neutral, for dark mode backgrounds.
    static final int
    A light neutral, for backgrounds.
    static final int
    A dark tone of the accent, for text on ACCENT_CONTAINER.
    static final int
    The secondary accent color.
    static final int
    The tertiary accent color.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    getColor(int index, int fallback)
    One palette entry, or the fallback when the platform has no palette.
    static int[]
    The palette, indexed by the constants of this class, or null when the platform has none.
    static boolean
    True when the platform supplies a dynamic palette.
    static void
    setImplementation(com.codename1.impl.CodenameOneImplementation impl)
    Invoked internally from Display, this method is for internal use only

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ACCENT

      public static final int ACCENT
      The primary accent color.
      See Also:
    • ACCENT_CONTAINER

      public static final int ACCENT_CONTAINER
      A light tone of the accent, for containers.
      See Also:
    • ON_ACCENT_CONTAINER

      public static final int ON_ACCENT_CONTAINER
      A dark tone of the accent, for text on ACCENT_CONTAINER.
      See Also:
    • SECONDARY

      public static final int SECONDARY
      The secondary accent color.
      See Also:
    • TERTIARY

      public static final int TERTIARY
      The tertiary accent color.
      See Also:
    • NEUTRAL_LIGHT

      public static final int NEUTRAL_LIGHT
      A light neutral, for backgrounds.
      See Also:
    • NEUTRAL_DARK

      public static final int NEUTRAL_DARK
      A dark neutral, for dark mode backgrounds.
      See Also:
    • COUNT

      public static final int COUNT
      The number of palette entries.
      See Also:
  • Method Details

    • setImplementation

      public static void setImplementation(com.codename1.impl.CodenameOneImplementation impl)

      Invoked internally from Display, this method is for internal use only

      Parameters
      • impl: implementation instance
    • isSupported

      public static boolean isSupported()

      True when the platform supplies a dynamic palette.

      Returns

      true when #getPalette() answers non-null

    • getPalette

      public static int[] getPalette()

      The palette, indexed by the constants of this class, or null when the platform has none. Entries a platform lacks repeat the accent.

      Returns

      a new array of COUNT RGB values, or null

    • getColor

      public static int getColor(int index, int fallback)

      One palette entry, or the fallback when the platform has no palette.

      Parameters
      • index: one of the constants of this class
      • fallback: the RGB value to answer without a palette
      Returns

      the RGB value