Enhanced Background Color Processing in CTA Asset View
Use the Background color search API for native advertising CTA assets
It is a function added in NAM SDK version 6.5.0. The API that could obtain the background color of the callToAction
button is added.
This button can be used in situations where the user has expressed interest (100% + 1-second exposure) for the callToAction
asset among the assets used while rendering native ads.
- Kotlin
- Java
lateinit var nativeAd: GfpNativeAd
lateinit var callToActionButton: Button
var callToActionHilightedBgColor: Int = Color.BLUE
val adLoader = GfpAdLoader.Builder(context, adParam)
.withAdListener(object: AdEventListener() {
// . . .
})
...
.withNativeAd(nativeAdOptions) { ad ->
this.nativeAd = ad
inflateNativeAd(adView, ad)
}
.build()
...
fun inflateNativeAd(parent: ViewGroup, nativeAd: GfpNativeAd) {
// . . .
callToActionButton = adView.findViewById(R.id.ad_call_to_action)
nativeAd.callToActionWithOption?.let { callToActionWithOption ->
callToActionButton.text = callToActionWithOption.text
callToActionWithOption.getHighlightedBgColor(context)?.let { highlightedBgColor ->
callToActionHilightedBgColor = highlightedBgColor
}
}
// . . .
}
GfpNativeAd nativeAd;
Button callToActionButton;
int callToActionHighlightedBgColor = Color.BLUE;
GfpAdLoader adLoader = new GfpAdLoader.Builder(context, adParam)
.withAdListener(new AdEventListener() {
// ...
})
// ...
.withNativeAd(nativeAdOptions, ad -> {
nativeAd = ad;
inflateNativeAd(adView, ad);
})
.build();
// ...
void inflateNativeAd(ViewGroup parent, GfpNativeAd nativeAd) {
// ...
callToActionButton = adView.findViewById(R.id.ad_call_to_action);
if (nativeAd.getCallToActionWithOption() != null) {
CallToActionWithOption callToActionWithOption = nativeAd.getCallToActionWithOption();
callToActionButton.setText(callToActionWithOption.getText());
Integer highlightedBgColor = callToActionWithOption.getHighlightedBgColor(context);
if (highlightedBgColor != null) {
callToActionHighlightedBgColor = highlightedBgColor;
}
}
// ...
}
The GfpNativeAd.getCallToActionWithOption()
method has a nullable return value. While the text value is guaranteed if the LabelOption
, which is the return value, is not null, the background color value that could be obtained through the getHighlightedBgColor(context)
method is nullable.
LabelOption
with a nullable background color value occurs in the following cases.
- When the response is from a C2S advertising provider that only transmits the string information corresponding to callToAction and cannot receive the background color values such as DFP, FAN, InMobi, and...
- When the callToAction response is an S2S advertisement response but does not have a background color value