Chat UITheme Manager
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);
Content copied to clipboard
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();
Content copied to clipboard
Properties
Functions
Link copied to clipboard
Registers a theme-change listener.
Link copied to clipboard
Switches to a custom theme that is stacked on top of a base built-in theme.
Link copied to clipboard
Switches to a registered built-in theme and applies it immediately.
Link copied to clipboard
Resolves a theme attribute to its actual resource ID.
Link copied to clipboard
Resolves a theme color attribute to an ARGB color integer.
Link copied to clipboard
Returns the currently active theme identifier.
Link copied to clipboard
Returns whether the system is currently in dark mode.
Link copied to clipboard
Unregisters a previously registered theme-change listener.