Native Ads: Google
Integrate native ads (Google)
NativeAdView
Native ad assets of GoogleMobileAds SDK are required to be encapsulated within a parent view of a specific type
NativeAdView.The same view must be passed to AATKit via the
NativeAdDatamethod:attachToLayout.
Also, Google displays the native ad main image using an instance of MediaView.
private NativeAdView containerView;
private TextView titleView;
private TextView descriptionView;
private MediaView mediaView;
private ImageView iconView;
private TextView advertiserView;
private TextView ctaView;private var containerView: NativeAdView? = null
private var titleView: TextView? = null
private var descriptionView: TextView? = null
private var mediaView: MediaView? = null
private var iconView: ImageView? = null
private var advertiserView: TextView? = null
private var ctaView: TextView? = nullBind Google Native Ad Assets
After getting a native ad from the NativeAdPlacement, you can follow this code example to bind the native ad assets:
private void setupGoogleAd(NativeAdData nativeAd) {
// Title
containerView.setHeadlineView(titleView);
titleView.setText(nativeAd.getTitle());
// Ad Icon
containerView.setIconView(iconView);
loadImage(iconView, nativeAd.getIconUrl());
// Body
containerView.setBodyView(descriptionView);
descriptionView.setText(nativeAd.getDescription());
// MediaView
containerView.setMediaView(mediaView); //Google SDK will fill the passed MediaView automatically
// Advertiser
containerView.setAdvertiserView(advertiserView);
advertiserView.setText(nativeAd.getAdvertiser());
// CallToAction
containerView.setCallToActionView(ctaView);
ctaView.setText(nativeAd.getCallToAction());
nativeAd.attachToLayout(containerView, mediaView, iconView, ctaView);
}private fun setupGoogleAd(nativeAd: NativeAdData) {
// Title
containerView.headlineView = titleView
titleView.text = nativeAd.title
// Ad Icon
containerView.iconView = iconView
loadImage(iconView, nativeAd.iconUrl)
// Body
containerView.bodyView = descriptionView
descriptionView.text = nativeAd.description
// MediaView
containerView.mediaView = mediaView //Google SDK will fill the passed MediaView automatically
// Advertiser
containerView.advertiserView = advertiserView
advertiserView.text = nativeAd.advertiser
// CallToAction
containerView.callToActionView = ctaView
ctaView.text = nativeAd.callToAction
nativeAd.attachToLayout(containerView, mediaView, iconView, ctaView)
}Change Native Ad AdChoicesIconPosition
You can choose from the following values to position the AdChoices icon within your native ad layout: TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT
AATKit.setAdChoicesIconPosition(AATKit.AdChoicesIconPosition.TOP_LEFT);AATKit.setAdChoicesIconPosition(AATKit.AdChoicesIconPosition.TOP_LEFT)Last updated