Native Ads Template - uc-union/union-ads-sdk-demo GitHub Wiki
Note: Be sure that SDK is initialzed correctly, see Initialize SDK.
Native Ad Template is the native template with style that most widely used. It's more simple than native ad. Union Ads SDK supply Native Ad Template in the form of Android View. Although the style and size are fixed, the theme can be customized. Developer can set the font , text color ,background color of Native Ad Template.
The sample code for use of Native Ad Template is as follows, refer to NativeTemplateFragment.java for more details.
Typeface font = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
AdRequestOption option = AdRequestOption.newNativeTemplateBuilder()
.backgroundColor(Color.BLACK)
.btnBackgroundColor(Color.BLUE)
.btnTextColor(Color.RED)
.descriptionTextColor(Color.GRAY)
.titleTextColor(Color.RED)
.typeFace(font)
.build();
final NativeTemplateAd nativeAd = new NativeTemplateAd( MainActivity.this);
parentView.addView(nativeAd);//add nativeAd to the UI tree.
nativeAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded(Ad ad) {
}
@Override
public void onAdClosed(Ad ad) {
}
@Override
public void onAdShowed(Ad ad) {
}
@Override
public void onAdClicked(Ad ad) {
}
@Override
public void onAdError(Ad ad, AdError adError) {
}
});
AdRequest adRequest = AdRequest.newBuilder()
.pub(<Pub>)
.withOption(option)
.build();
nativeAd.loadAd(adRequest);Note:
- NativeTemplateAd is a normal Android
View, don't forget to add it into UI tree.
<Pub>is a unique id for the ad placement, please get it from uc union manager console or your BD
Once you run the demo project and show the native ad template, you should see something like this:

-
See FAQ to know about the frequently asked questions.
-
See API reference to explore all APIs in Union Ad SDK.
