Code sample to enable dark mode in Android | Community
Skip to main content

Can I please have a code sample on how to implement dark mode (or switch themes) for Android. E.g. something like

import io.intercom.android.sdk.ui.theme.ThemeMode;

Intercom.client().setThemeMode(ThemeMode.DARK);

I noted that Dark Mode was enabled on Android SDK v17.0.0

Hi ​@Ron Dul ! Ebenezer here from Engineering Support👋.

  • The SDK uses a ThemeManager to determine the current theme mode (light, dark, or system/default).
  • The IntercomTheme composable applies the correct color palette based on the theme mode.
  • Utility functions are provided to select the appropriate color for the current theme, both in Compose and non-Compose contexts.
  • You can override the theme mode at runtime (e.g., to allow users to toggle between light and dark modes within your app).

You can set the theme mode using the ThemeManager. For example, to force dark mode:

import io.intercom.android.sdk.ui.theme.ThemeManager
import io.intercom.android.sdk.ui.theme.ThemeMode

// To force dark mode
ThemeManager.setSessionOverride(ThemeMode.DARK)

// To force light mode
ThemeManager.setSessionOverride(ThemeMode.LIGHT)

// To follow the system theme
ThemeManager.setSessionOverride(ThemeMode.SYSTEM)

 

If you are using Jetpack Compose, wrap your Intercom Messenger UI in the IntercomTheme composable. The theme will automatically adapt based on the current theme mode:

import io.intercom.android.sdk.ui.theme.IntercomTheme

IntercomTheme {
    // Place your Intercom Messenger UI here
}

 

If you need to select colors manually (e.g., for custom UI elements), use the provided utility:

import io.intercom.android.sdk.utilities.ThemeUtils

val color = ThemeUtils.selectColorForTheme(context, "#FFFFFF", "#14161a")


Thank you, that is very helpful.


When using Intercom Android SDK 17.1.0 we aren’t able to import the ThemeManager and ThemeMode — as if the “ui” folder isn’t included in the SDK package?

Error: “Cannot resolve symbol 'theme'”

Many thanks


Reply