Skip to main content

Dark Theme

The NAM SDK supports dark themes for certain S2S ads processed through the NDA module. However, not all ad formats support dark themes. You should confirm with the NAM administrator whether the ad formats used in your app support dark themes.

This guide explains how to apply the dark theme in the NAM SDK.

How to Apply the Dark Theme

The NAM SDK provides three dark theme-related configuration values:

ValueDescription
ResolvedTheme.SYSTEMApplies the DayNight theme based on the system settings of the device.
ResolvedTheme.LIGHTAlways applies a light theme, regardless of the system settings. (Default if not set)
ResolvedTheme.DARKAlways applies a dark theme, regardless of the system settings.

The above dark theme-related configuration values can be applied in two ways: globally or individually for each ad loader.

1. Global Configuration

To apply the same dark theme to all ads in the app, you can use the global configuration method. SdkProperties allows you to configure options for each mediation network, including NdaProviderOptions. Within NdaProviderOptions, you can set the theme property to configure the dark theme.

The following example demonstrates how to globally set the dark theme:

GfpSdk.setSdkProperties(GfpSdk.getSdkProperties().buildUpon()
...
.addProviderOptions(NdaProviderOptions.Builder().setTheme(ResolvedTheme.DARK).build())
.build())

2. Individual Ad Configuration

To apply the dark theme to specific ads only, you can use the options provided for each ad format to configure the dark theme. When this configuration is applied, the globally set dark theme configuration is ignored, and the specified dark theme configuration is prioritized for the respective ad.

The following example demonstrates how to configure a native simple ad requested via GfpAdLoader to always use the dark theme.

val nativeSimpleAdOptions = GfpNativeSimpleAdOptions.Builder()
.setTheme(ResolvedTheme.DARK)
.build()
val adLoader = GfpAdLoader.Builder(activity, adParam)
.withAdListener(object: AdEventListener {
...
})
.withNativeSimpleAd(nativeSimpleAdOptions) { nativeSimpleAd ->
...
}
.build()

LazyTheme

The previously explained dark theme configuration methods may not immediately reflect changes to the DayNight setting if the setting is changed after the ad has already been loaded. In such cases, the theme configuration from when the ad was initially loaded may persist.

Starting from NAM SDK 6.1.1, LazyTheme is supported to address this issue. LazyTheme allows the dark theme to dynamically change based on DayNight setting changes even after the ad has been loaded. This ensures that ads are displayed according to the current theme, even if the user changes the system theme or the app theme while the app is running.

The following example demonstrates how to use LazyTheme in native ads to apply the required theme value at the time it needs to be applied.

val nativeAdOptions = GfpNativeAdOptions.Builder()
...
.setTheme(LazyTheme {
// This method is called when the theme value needs to be actually
// applied and should return the currently required theme value.
// The following example demonstrates how to return the LIGHT theme.
ResolvedTheme.LIGHT
})
.build()
val adLoader = GfpAdLoader.Builder(requireActivity(), adParam)
.withNativeAd(nativeAdOptions) { nativeAd ->
...
}
.build()