ChatUIThemeManager

public class ChatUIThemeManager

Theme manager for the ChatUI SDK.

Manages theme switching and resource resolution for the ChatUI components, supporting multiple themes and automatic light/dark mode adaptation.

Core features

  • Built-in theme: provides the lively theme (LIVELY_THEME), which automatically follows the system light/dark mode
  • Custom themes: developers can register and extend custom themes with light/dark variants and theme stacking
  • System follow: automatically switches with the system light/dark mode
  • Resource resolution: resolves theme attribute IDs and color values based on the current theme and dark-mode state
  • Auto-apply: applies themes to all Activities via
  • Theme listeners: notifies registered OnThemeListeners on every switch

Dark-mode note

On some devices, toggling the system dark mode while the app is in the background may not take effect immediately because the system still reports the old value until the app restarts.

Recommended solution: If your app uses the AppCompat library, call AppCompatDelegate.setDefaultNightMode(nightMode) in Application.onCreate() to ensure timely mode switching:

// Follow system dark mode
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);

// Force light mode
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

// Force dark mode
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

Quick start

// 1. Switch to the lively theme (auto light/dark)
ChatUIThemeManager.changeInnerTheme(context, ChatUIThemeManager.LIVELY_THEME);

// 2. Register a custom theme with light/dark variants
ChatUIThemeManager.addTheme("CUSTOM_THEME",
    R.style.MyCustomLightTheme,
    R.style.MyCustomDarkTheme
);

// 3. Switch to the custom theme, stacked on top of the lively theme
ChatUIThemeManager.changeCustomTheme(context, "CUSTOM_THEME", ChatUIThemeManager.LIVELY_THEME);

// 4. Resolve a theme attribute to a resource ID at runtime
int bgResId = ChatUIThemeManager.getAttrResId(context, R.attr.nc_conversation_bg);
view.setBackgroundResource(bgResId);

// 5. Query the current theme
String currentTheme = ChatUIThemeManager.getCurrentThemeName();

Types

Link copied to clipboard
public interface OnThemeListener
Listener for theme-change events.

Properties

Link copied to clipboard
public final static String LIVELY_THEME
Lively theme — modern UI that automatically follows the system light/dark mode.

Functions

Link copied to clipboard
public static void addTheme(String themeType, int lightStyleResId, int darkStyleResId)
Registers a theme with light and dark style variants.
Link copied to clipboard
Registers a theme-change listener.
Link copied to clipboard
public static void changeCustomTheme(Context context, String customThemeType, String baseOnTheme)
Switches to a custom theme that is stacked on top of a base built-in theme.
Link copied to clipboard
public static void changeInnerTheme(Context context, String themeType)
Switches to a registered built-in theme and applies it immediately.
Link copied to clipboard
public static int getAttrResId(Context context, int attrId)
Resolves a theme attribute to its actual resource ID.
Link copied to clipboard
public static int getColorFromAttrId(Context context, int attrId)
Resolves a theme color attribute to an ARGB color integer.
Link copied to clipboard
public static String getCurrentThemeName()
Returns the currently active theme identifier.
Link copied to clipboard
public static boolean isSystemInDarkMode(Context context)
Returns whether the system is currently in dark mode.
Link copied to clipboard
Unregisters a previously registered theme-change listener.