set Color Scheme
Themes the SDK's UI programmatically with a Compose UiColorScheme, instead of the XML theme attributes. The scheme colors the main toolbar and the SDK screens this UI shows, such as the outline view with its bookmark, annotation and attachment lists, document info, the tab bar, the share menu, settings, the switches in the custom stamp creator and AI Assistant. Pass null to clear it and fall back to the XML theme attributes. Works the same on PdfActivity and on a PdfUiFragment embedded in a custom activity.
The annotation creation toolbar, its submenus and its borders follow the scheme's
contextualToolbar colors. UiColorScheme.fromXmlTheme() fills them from the
pspdf__contextualToolbarStyle attributes and copy() keeps them, so a scheme copied from it keeps that toolbar's XML colors however the copy changes the main toolbar. Set
contextualToolbar as well when the two toolbars are meant to match.
The scheme is stored on the hosting activity, so two PdfUiFragments in one activity share it: the last one set wins, for the toolbars of both fragments as well as their other screens.
A main-toolbar scheme set with the deprecated
PdfActivity#setMainToolbarColorScheme(UiColorScheme) keeps coloring that toolbar over this one. Pass null to it to have the toolbar follow this scheme.
Compose content wrapped in NutrientTheme without a colorScheme uses this scheme too, so it matches the SDK screens of the same activity. A colorScheme passed to NutrientTheme takes precedence over it.
XML theming remains the default. Build the scheme from UiColorScheme.fromXmlTheme(), which returns the colors the XML theme attributes give today, and copy the parts you want to change. Starting from the Material 3 defaults instead switches every screen above to those colors.
The scheme is used in light and in dark mode alike. To follow the system's light/dark switch, set a pair with setColorScheme or setColorScheme instead.
Parameters
the color scheme to apply, or null to use the XML theme attributes.
Sets one color scheme for light mode and one for dark mode. The SDK's screens show whichever matches the current configuration's night mode and switch with it, so the app doesn't have to set the scheme again on a configuration change. Everything else is as for setColorScheme: the pair is stored on the hosting activity, the last call wins, and setColorScheme(null) clears it.
Which of the two shows follows the theme applied to the activity, so the SDK's Compose screens agree with its views: light with a theme that declares itself light (isLightTheme, which every AppCompat and Material Components theme declares), dark with one that declares itself dark. So a DayNight theme switches with the device, and ThemeMode.NIGHT shows dark whatever the device's night mode wherever it applies a dark theme: the configuration's themeDark(), or the SDK's own dark theme when the activity has no manifest theme. The SDK's default theme is light only: an app that keeps it and wants dark on a dark device passes a DayNight theme to PdfActivityConfiguration.Builder.theme() or sets ThemeMode.NIGHT. A theme that declares neither, such as a framework theme before API 29, follows the device's night mode.
Build each scheme with UiColorScheme.fromMaterial() from a Material 3 color scheme, or with UiColorScheme.fromXmlTheme(Context) from the light and the dark theme, such as the ones passed to PdfActivityConfiguration.Builder.theme() and themeDark(), and copy the parts you want to change. Both are plain functions, so this can be called in onCreate():
setColorScheme(
UiColorScheme.fromXmlTheme(new ContextThemeWrapper(this, R.style.MyTheme)),
UiColorScheme.fromXmlTheme(new ContextThemeWrapper(this, R.style.MyTheme_Dark)));
A ContextThemeWrapper reads resources in the activity's current night mode. When a theme's colors come from -night resources, call applyOverrideConfiguration() on its wrapper with a configuration whose uiMode is UI_MODE_NIGHT_YES (or UI_MODE_NIGHT_NO for the light one).
Parameters
the color scheme for light mode.
the color scheme for dark mode.
Sets one Material 3 color scheme for light mode and one for dark mode: setColorScheme with UiColorScheme.fromMaterial() applied to each, so every SDK screen takes its colors from the Material roles. This is the whole theming call for an app on Material 3; for example setColorScheme(lightColorScheme(primary = ...),
darkColorScheme(primary = ...)), or setColorScheme(dynamicLightColorScheme(this),
dynamicDarkColorScheme(this)) for dynamic color.
Parameters
the Material 3 color scheme for light mode.
the Material 3 color scheme for dark mode.