Native Ads: Huawei
Integrate native ads (Huawei)
private com.huawei.hms.ads.nativead.NativeView containerView;
private TextView titleView;
private TextView descriptionView;
private com.huawei.hms.ads.nativead.MediaView mediaView;
private ImageView iconView;
private TextView ctaView;private var containerView: com.huawei.hms.ads.nativead.NativeView? = null
private var titleView: TextView? = null
private var descriptionView: TextView? = null
private var mediaView: com.huawei.hms.ads.nativead.MediaView? = null
private var iconView: ImageView? = null
private var ctaView: TextView? = nullprivate void setupHuaweiAd(NativeAdData nativeAd) {
// TODO: create the container view and subviews from layout file
// Title
containerView.setTitleView(titleView);
titleView.setText(nativeAd.getTitle());
// Ad Icon
containerView.setIconView(iconView);
loadImage(iconView, nativeAd.getIconUrl());
// Body
containerView.setAdSourceView(descriptionView);
descriptionView.setText(nativeAd.getDescription());
// MediaView
containerView.setMediaView(mediaView); //Huawei SDK will fill the passed MediaView automatically
// CallToAction
containerView.setCallToActionView(ctaView);
ctaView.setText(nativeAd.getCallToAction());
nativeAd.attachToLayout(containerView, mediaView, iconView, ctaView);
}Last updated