NowUIAdaptiveColor - Android

  • Release version: Yokohama
  • Updated January 30, 2025
  • 1 minute to read
  • The NowUIAdaptiveColor interface provides functions that return an integer or hexadecimal color value based on the calling device's theme mode setting.

    It returns the value for the darkColor theme if dark mode is enabled on the user's device and the value for the lightColor theme for all other scenarios.

    NowUIAdaptiveColor - getColor(context: Context?)

    Returns an integer color value based on the calling device's theme mode setting.

    It returns the value for the darkColor theme if dark mode is enabled on the user's device and the value for the lightColor theme for all other scenarios.

    Table 1. Parameters
    Name Type Description
    context Object Comma-separated list of colors for which to return the color values.

    For examples: NowUIAdaptiveColor(lightColor = Color.BLACK, darkColor = Color.WHITE)

    Table 2. Returns
    Type Description
    Integer Color value for the passed color.

    The following code example shows how to use this function.

    lifecycleScope.launch {
      sdkManager.getNowWebService()?.launch(this@MainActivity, URL("https://instance-name.service-now.com"), object : NowWebTheme {
        override val brand: NowUIAdaptiveColor
          // Override lightColor only. For dark theme default color will be used
          get() = NowUIAdaptiveColor(lightColor = Color.BLACK)
    
        override val primary: NowUIAdaptiveColor
          // Override both lightColor and darkColor
           get() = NowUIAdaptiveColor(lightColor = Color.BLACK, darkColor = Color.WHITE)
    
        // override the rest of color variables
      })
    }

    NowUIAdaptiveColor - toStringColor(context: Context?)

    Returns a hexadecimal color value based on the calling device's theme mode setting.

    Table 3. Parameters
    Name Type Description
    context Object Comma-separated list of colors for which to return the color values.

    For examples: NowUIAdaptiveColor(lightColor = Color.BLACK, darkColor = Color.WHITE)

    Table 4. Returns
    Type Description
    String Hexadecimal color value for the passed colors.

    The following code example shows how to use this function.

    val adaptiveColor = NowUIAdaptiveColor(lightColor = Color.BLACK, darkColor = Color.WHITE)
    adaptiveColor.toStringColor(context)