Native/Icon
Custom ads with a look and feel that blend naturally with your app.
Introduction
Rendering Method
Type | Description |
---|---|
Self Rendering | The ad platform returns the type of ad creatives assembled by the developer. The type selection needs to be consistent with the Hisavana platform, otherwise the request will fail. |
Template Rendering | The advertising platform returns the rendered view, which can be displayed directly on the page by adding it to a container. |
Self Rendering:

Template Rendering: Support the context of the upper picture, the upper text of the lower picture, the right text of the left picture, the left text of the right picture, vertical picture and full screen picture, You can fine-tune the display style.
Above and below | Below picture above | Picture on the left and text on the right |
![]() | ![]() | ![]() |
It is recommended not to limit the layout height |
Right image, left text | Vertical image | Full screen image |
---|---|---|
![]() | ![]() | ![]() |
It is recommended not to limit the layout height | It is recommended not to limit the layout height, it is recommended to limit the layout width | It is recommended that the layout width and height be match_parent |
Advertisement Type
Type | Description |
---|---|
Native | The content area includes custom styles such as ad labels, logos, main images, titles, descriptions, buttons, etc. The default number of requested ads is 1 (default is recommended). When the onAdLoaded callback is successful, the first ad in the array will be displayed. |
Icon | Normally, the content area only contains the Icon image. The default number of requested ads is 1, and the maximum number of requested ads is 5. When the onAdLoaded callback is successful, the ads in the array will be displayed. |
Load Ads
Native: Please set the corresponding parameters and listener callback.
// Initialize Ntaive ad object, where "native_id" is the Native ad slot ID
TNative tNativeAd = new TNative("native_id");
// Set ad listener
tNativeAd.setListener(new TAdListener());
// Load ad
tNativeAd.loadAd();
Icon: Please set the corresponding parameters and listener callback.
// Initialize Ntaive ad object, where "icon_id" is the Icon ad slot ID
TNative tNativeAd = new TNative("icon_id");
// Set ad listener
tNativeAd.setListener(new TAdListener());
// Set whether it is an ad slot of ICON type
tNativeAd.setLoadIcon(true);
// Set the number of requested ads
tNativeAd.setAdCount(4);
// Load ads
tNativeAd.loadAd();
Ad listener
// Ad listener, listens to the callbacks of ad request timeout, loading completion (filling), display, click, exception, and close actions
private static class TAdListener extends AdListener {
// Abnormal callback (applicable ad slots: all ad slots)
@Override
public void onError(TaErrorCode adError) {
Log.d(TAG,"Ad failed callback");
}
// Loading completion callback (applicable ad slots: Native/Icon)
@Override
public void onAdLoaded(List<TaNativeInfo> adInfos) {
Log.d(TAG,"Ad loaded callback");
}
// Click callback (applicable ad slots: Native/Icon)
@Override
public void onNativeAdClick(TaNativeInfo taNativeInfo) {
Log.d(TAG,"Ad click callback");
}
// Display callback (applicable ad slots: Native/Icon)
@Override
public void onNativeAdShow(TaNativeInfo taNativeInfo) {
Log.d(TAG,"Ad show callback");
}
// Request timeout callback (applicable ad slots: all ad slots)
@Override
public void onTimeOut() {
Log.d(TAG,"Ad request timeout callback");
}
// Close callback (applicable ad slots: Native/Icon)
@Override
public void onAdClosed(TaNativeInfo taNativeInfo) {
Log.d(TAG,"Ad close callback");
}
}
Display Ads
Please display the TNativeView object.
Emphasis
Native: For ads that jump to the PalmStore landing page, storeMarkView (app store logo) must be added, otherwise it will affect the jump link for downloading ads.
Icon: Usually, there is no need to set the main image, only the icon.
For details, please refer to TaNativeInfo
Reminder: If you want to display Self Rendering Native ads that comply with Russian regulations, see Show Russian Compliant Ads.
Step One: Create a TNativeView object.
// Please add TNativeView in the xml of the parent layout
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.cloud.hisavana.sdk.api.view.TNativeView
android:id="@+id/native_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
// Bind views in xml layout
TNativeView nativeView = findViewById(R.id.native_view);
or
// Manually create a TNativeView object and add it to the parent layout
TNativeView nativeView = new TNativeView(this);
Step Two: Add a Sub-layout File
Native: Added a sub-layout file native_install.xml for Native ad elements, where the icon in the ad element is rendered with ImageView and the large image is rendered with MediaView. For details, please refer to Add the sub-layout file native_install.xml of the Native advertising element, in which the icon in the advertising element is rendered with ImageView, and the large image is rendered with MediaView. For details, Please refer to Advanced Settings
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ad_unit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/item_background">
<com.cloud.hisavana.sdk.api.view.MediaView
android:id="@+id/coverview"
android:layout_width="match_parent"
android:layout_height="200dp"
tools:background="#22000000"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<com.cloud.hisavana.sdk.api.view.AdChoicesView
android:id="@+id/ad_choice"
android:layout_width="@dimen/dp_12"
android:layout_height="@dimen/dp_12"
app:layout_constraintLeft_toRightOf="@+id/native_ad"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/native_ad"
android:layout_width="@dimen/dp_12"
android:layout_height="@dimen/dp_12"
android:src="@drawable/hisavana_ad_big"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
</ImageView>
<ImageView
android:id="@+id/native_ad_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
tools:background="#22000000"
app:layout_constraintTop_toBottomOf="@+id/coverview"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/native_ad_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:ellipsize="end"
android:lines="1"
android:textColor="@android:color/black"
android:textSize="18sp"
tools:text="Title"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toBottomOf="@+id/coverview"
app:layout_constraintLeft_toRightOf="@+id/native_ad_icon"/>
<TextView
android:id="@+id/native_ad_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@android:color/black"
android:textSize="15sp"
tools:text="des\ndes"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toBottomOf="@+id/native_ad_title"
app:layout_constraintLeft_toRightOf="@+id/native_ad_icon"/>
<TextView
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rating"
app:layout_constraintTop_toBottomOf="@+id/native_ad_body"
android:layout_marginLeft="10dp"
app:layout_constraintLeft_toRightOf="@+id/native_ad_icon"/>
<Button
android:id="@+id/call_to_action"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="DOWNLOAD NOW!"
android:textAllCaps="false"
android:layout_marginTop="10dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rating" />
<!-- For ads that jump to the PalmStore landing page, storeMarkView (app store logo) must be added, otherwise it will affect the jump link for downloading ads. -->
<com.cloud.hisavana.sdk.api.view.StoreMarkView
android:id="@+id/ps_mark_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/call_to_action"
app:layout_constraintEnd_toEndOf="parent" />
<com.cloud.hisavana.sdk.api.view.AdCloseView
android:id="@+id/hisavana_ad_close"
android:layout_width="20dp"
android:layout_height="20dp"
tools:ignore="MissingConstraints"
android:layout_margin="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Icon: Add the sub-layout file item_icon.xml of the Icon advertising element
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ad_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/item_background">
<ImageView
android:id="@+id/native_ad_icon"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Step Three: Data and view binding
Native
Binding: as shown below
// Please refer to the processing method in the ad listener "onAdLoaded(List<TaNativeInfo> adInfos)"
@Override
public void onAdLoaded(List<TaNativeInfo> adInfos) {
Log.d(TAG,"Ad request successful");
TaNativeInfo ad;
if (adInfos != null && !adInfos.isEmpty()) {
for (int i = 0; i < adInfos.size(); i++) {
ad = adInfos.get(i);
if (ad == null) {
continue;
}
if (tNativeAd.isReady(ad)) {
inflateView(ad, tNativeAd, nativeView);
break;
} else {
Log.d(TAG, "Ad has expired");
}
}
}
}
Self Rendering:
// Self Rendering ad, bind fill data here
private void inflateView(TaNativeInfo adNativeInfo, TNative nativeAd, TNativeView nativeView) {
ConstraintLayout adView = (ConstraintLayout) LayoutInflater.from(nativeView.getContext()).inflate(R.layout.native_install, null);
// Bind icon control
ImageView icon = adView.findViewById(R.id.native_ad_icon);
// Bind the advertiser image control
MediaView mediaView = adView.findViewById(R.id.coverview);
// Bind advertising target control
AdChoicesView adChoicesView = adView.findViewById(R.id.ad_choice);
// Bind ad closing control
AdCloseView adCloseView = adView.findViewById(R.id.hisavana_ad_close);
// Required, bind the app store logo control
StoreMarkView storeMarkView = adView.findViewById(R.id.store_mark_view);
// Bind title control
TextView title = adView.findViewById(R.id.native_ad_title);
// Bind description control
TextView des = adView.findViewById(R.id.native_ad_body);
// Bind responsive action controls
Button calltoaction = adView.findViewById(R.id.call_to_action);
TextView rating = adView.findViewById(R.id.rating);
nativeView.destroy();
// Set icon control
nativeView.setIconView(icon);
// Set the advertiser image control
nativeView.setMediaView(mediaView, ImageView.ScaleType.FIT_XY);
// Set advertising target controls
nativeView.setAdChoiceView(adChoicesView);
// Set ad closing controls
nativeView.setAdCloseView(adCloseView);
// Required, set the app store identification control
nativeView.setPsMarkView(storeMarkView);
// Add ad view
nativeView.addView(adView);
title.setText(adNativeInfo.getTitle());
des.setText(adNativeInfo.getDescription());
calltoaction.setText(adNativeInfo.getCtatext());
if (!TextUtils.isEmpty(adNativeInfo.getRating())) {
rating.setText("R : " + adNativeInfo.getRating());
}
List<View> adContains = new ArrayList<>();
adContains.add(title);
adContains.add(icon);
adContains.add(mediaView);
adContains.add(calltoaction);
adContains.add(des);
adContains.add(adView);
adContains.add(adCloseView);
adContains.add(storeMarkView);
nativeView.setupViews(adNativeInfo);
tNativeAd.registerViews(nativeView, adContains, adNativeInfo);
}
Template Rendering:
private void inflateView(TaNativeInfo adNativeInfo, TNative nativeAd, TNativeView nativeView) {
// template object
TemplateStyle templateStyle;
// Boolean type: "isChangeStyle"
if (isChangeStyle) {
// You can fine-tune the module yourself
templateStyle = new TemplateStyle.Builder()
.titleSize(20).titleColor(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_0051E1)).isTitleBold(0)
.descColor(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_0051E1)).descSize(20).isDescBold(1)
.callToAction_text_color(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_0051E1)).callToAction_text_isBold(1).callToAction_text_size(20)
.callToAction_background_color(CoreUtil.getContext().getResources().getColor(R.color.ad_button_bg_color))
.callToAction_corner_radius(0).callToAction_stroke_color(CoreUtil.getContext().getResources()
}.getColor(R.color.hisavana_ad_color_0051E1)).callToAction_stroke_width(5)
//.callToAction_background_shape(CoreUtil.getContext().getResources().getDrawable(R.drawable.hisavana_bg_shadow))
.background(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_787878))
.build();
} else {
// Use default template
templateStyle = new TemplateStyle.Builder().build();
}
nativeView.setTemplateStyle(templateStyle);
nativeAd.registerViews(nativeView, adNativeInfo);
}
Media Configuration Platform Settings

Icon
Binding: as shown below
// Please refer to the processing method in the ad listener "onAdLoaded(List<TaNativeInfo> adInfos)"
@Override
public void onAdLoaded(List<TaNativeInfo> adInfos) {
Log.d(TAG,"Ad request successful");
TaNativeInfo ad;
if (adInfos != null && !adInfos.isEmpty()) {
for (int i = 0; i < adInfos.size(); i++) {
ad = adInfos.get(i);
if (ad == null) {
continue;
}
// The example only displays 1 icon ad. If you need to display multiple, you can add bindings through RecyclerView
if (tNativeAd.isReady(ad)) {
inflateView(ad, tNativeAd, nativeView);
break;
} else {
Log.d(TAG, "Ad has expired");
}
}
}
}
// Bind fill data here
private void inflateView(TaNativeInfo adNativeInfo, TNative nativeAd, TNativeView nativeView) {
ConstraintLayout adView = (ConstraintLayout) LayoutInflater.from(nativeView.getContext()).inflate(R.layout.item_icon, null);
// Bind icon control
ImageView icon = adView.findViewById(R.id.native_ad_icon);
// Set icon control
nativeView.setIconView(icon);
// Add ad view
nativeView.addView(adView);
List<View> adContains = new ArrayList<>();
adContains.add(icon);
adContains.add(adView);
tNativeAd.registerViews(nativeView, adContains, adNativeInfo);
}
Destroy Ads
Please recycle ads in time, otherwise the App will cause memory leaks.
Native:
@Override
public void onAdClosed(TaNativeInfo taNativeInfo) {
// After the ad is closed, if you will no longer use it, it is recommended that you release the view and ad objects in time to avoid memory leaks.
if(nativeView != null){
nativeView.destroy();
taNativeInfo.destroy();
}
}
// After exiting the advertising scene, please destroy the advertising object.
@Override
protected void onDestroy() {
super.onDestroy();
// Release TaNativeInfo resources, "adInfos" is the list data in onAdLoaded(List<TaNativeInfo> adInfos)
for (TaNativeInfo taNativeInfo : adInfos) {
if(taNativeInfo != null){
taNativeInfo.destroy();
}
}
adInfos.clear();
//Container resource release
if (nativeView != null) {
nativeView.destroy();
}
// Release the advertisement object
if (nativeAd != null) {
nativeAd.destroy();
}
}
Icon:
// After exiting the ad scene, please destroy the ad object.
@Override
protected void onDestroy() {
super.onDestroy();
// Release TaNativeInfo resources, "adInfos" is the list data in onAdLoaded(List<TaNativeInfo> adInfos)
for (TaNativeInfo taNativeInfo : adInfos) {
if(taNativeInfo != null){
taNativeInfo.destroy();
}
}
adInfos.clear();
// Container resource release
if (nativeView != null) {
nativeView.destroy();
}
// Ad object release
if (tNativeAd != null) {
tNativeAd.destroy();
}
}
Other APIs
API call | Introduce |
---|---|
tNativeAd.setLoadIcon(boolean isLoadIcon) | If the current code bit type to be requested is ICON, set to true, default false |
tNativeAd.setAdCount(int adCount) | The number of currently requested ads, 1 by default, up to 5 (when the code bit type is ICON, multiple ads can be requested at one time) |
tNativeAd.isAdValid() | Whether the current ad is within the validity period |
tNativeAd.isLoaded(TaNativeInfo adNativeInfo) | Whether the current ad is loaded successfully |
adNativeInfo.isOfflineAd() | Is the current ad offline |
Advanced Settings
Required ad elements

Field | Description | Native | Icon |
---|---|---|---|
native_ad | Advertising indicator to clearly indicate that the unit is an ad | Required | Optional |
ad_choice | Advertiser's logo | Required | Optional |
hisavana_ad_close | To close ad content | Optional | |
ps_mark_view | A logo that can be used to pull up the app store | Required (PS ads) | |
coverview | The main content area (images, videos) that displays the ad | Required | |
native_ad_icon | Ad icon, a small app icon with a square aspect ratio (1:1) | Optional | Required |
native_ad_title | The main title text | Optional | |
native_ad_body | Secondary body text (e.g., article or app description) | Optional | |
call_to_action | Button or text field that encourages users to take action (e.g., "Visit site" or "Install"). You can display an app download icon instead of a button or text | Optional |
Displaying Russian Compliant Ads
Developers who launch products in Russia and monetize through Hisavana (integrating Hisavana SDK) must strictly comply with Russian advertising laws.
Hisavana SDK 3.0.8 and above support displaying ads that comply with Russian advertising regulations. You need to perform some additional integration-related operations when Self Rendering Native ads.
The main integration differences are in the Display Ads section, particularly in Step Two and Step Three. We need to replace the display method of the AD badge view and add a Disclaimer view.
Reminder: The term
universal version
refers to the non-Russian compliant version.
Step One: Create a TAdNativeView object
As above.
Step Two: Add a Sub-layout File
Add a sub-layout file native_install.xml for Native ad elements, where the ad element's icon is rendered with ImageView, and the large image is rendered with MediaView. For details, please refer to Advanced Settings
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ad_unit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/item_background"
android:orientation="vertical">
<com.cloud.hisavana.sdk.api.view.MediaView
android:id="@+id/coverview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:background="#22000000" />
<!-- Mandatory: Disclaimer View for Russian Compliant Version -->
<com.cloud.hisavana.sdk.api.view.AdDisclaimerView
android:id="@+id/ad_disclaimer_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="@id/coverview"
app:layout_constraintEnd_toEndOf="@id/coverview"
app:layout_constraintBottom_toBottomOf="@id/coverview" />
<com.cloud.hisavana.sdk.api.view.AdChoicesView
android:id="@+id/ad_choice"
android:layout_width="@dimen/ad_badge_height"
android:layout_height="@dimen/ad_badge_height"
app:layout_constraintEnd_toStartOf="@+id/ad_badge_view"
app:layout_constraintTop_toTopOf="parent" />
<!-- Universal version AD badge. If you are upgrading from the universal version, you need to replace the ImageView here with the following AdBadgeView. -->
<!-- <ImageView-->
<!-- android:id="@+id/native_ad"-->
<!-- android:layout_width="@dimen/dp_12"-->
<!-- android:layout_height="@dimen/dp_12"-->
<!-- android:src="@drawable/hisavana_ad_big"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintEnd_toStartOf="@+id/hisavana_ad_close">-->
<!-- </ImageView>-->
<!-- Mandatory: AD Badge for Russian Compliant Version -->
<com.cloud.hisavana.sdk.api.view.AdBadgeView
android:id="@+id/ad_badge_view"
android:layout_width="wrap_content"
android:layout_height="@dimen/ad_badge_height"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/hisavana_ad_close">
</com.cloud.hisavana.sdk.api.view.AdBadgeView>
<ImageView
android:id="@+id/native_ad_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
tools:background="#22000000"
app:layout_constraintTop_toBottomOf="@+id/coverview"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/native_ad_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:ellipsize="end"
android:lines="1"
android:textColor="@android:color/black"
android:textSize="18sp"
tools:text="Title"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
app:layout_constraintTop_toBottomOf="@+id/coverview"
app:layout_constraintLeft_toRightOf="@+id/native_ad_icon"/>
<TextView
android:id="@+id/native_ad_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@android:color/black"
android:textSize="15sp"
tools:text="des\ndes"
android:layout_marginStart="10dp"
app:layout_constraintTop_toBottomOf="@+id/native_ad_title"
app:layout_constraintLeft_toRightOf="@+id/native_ad_icon"/>
<TextView
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rating"
app:layout_constraintTop_toBottomOf="@+id/native_ad_body"
android:layout_marginStart="10dp"
app:layout_constraintLeft_toRightOf="@+id/native_ad_icon"/>
<Button
android:id="@+id/call_to_action"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="DOWNLOAD NOW!"
android:textAllCaps="false"
android:layout_marginTop="10dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rating" />
<com.cloud.hisavana.sdk.api.view.StoreMarkView
android:id="@+id/ps_mark_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/call_to_action"
app:layout_constraintEnd_toEndOf="parent" />
<com.cloud.hisavana.sdk.api.view.AdCloseView
android:id="@+id/hisavana_ad_close"
android:layout_width="@dimen/ad_badge_height"
android:layout_height="@dimen/ad_badge_height"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Step Three: Data and view binding
// Please refer to the handling method in the ad listener "onAdLoaded(List<TaNativeInfo> adInfos)"
@Override
public void onAdLoaded(List<TaNativeInfo> adInfos) {
Log.d(TAG,"Ad request successful");
TaNativeInfo ad;
if (adInfos != null && !adInfos.isEmpty()) {
for (int i = 0; i < adInfos.size(); i++) {
ad = adInfos.get(i);
if (ad == null) {
continue;
}
if (tNativeAd.isReady(ad)) {
inflateView(ad, tNativeAd, nativeView);
break;
} else {
Log.d(TAG, "The ad has expired");
}
}
}
}
Self Rendering
// Self Rendering ads, bind and populate data here
private void inflateView(TaNativeInfo adNativeInfo, TNative nativeAd, TNativeView nativeView) {
ConstraintLayout adView = (ConstraintLayout) LayoutInflater.from(nativeView.getContext()).inflate(R.layout.native_install, null);
// Bind icon control
ImageView icon = adView.findViewById(R.id.native_ad_icon);
// Bind main ad image control
MediaView mediaView = adView.findViewById(R.id.coverview);
// Bind ad badge control
AdChoicesView adChoicesView = adView.findViewById(R.id.ad_choice);
// Bind ad close control
AdCloseView adCloseView = adView.findViewById(R.id.hisavana_ad_close);
// Mandatory: Bind app store logo control
StoreMarkView storeMarkView = adView.findViewById(R.id.store_mark_view);
// Bind title control
TextView title = adView.findViewById(R.id.native_ad_title);
// Bind description control
TextView des = adView.findViewById(R.id.native_ad_body);
// Bind call to action control
Button calltoaction = adView.findViewById(R.id.call_to_action);
TextView rating = adView.findViewById(R.id.rating);
// Mandatory: Bind Russian Compliant Version AD Badge
AdBadgeView adBadgeView = adView.findViewById(R.id.ad_badge_view);
// Mandatory: Bind Russian Compliant Version Disclaimer
AdDisclaimerView adDisclaimerView = adView.findViewById(R.id.ad_disclaimer_view);
nativeView.destroy();
// 设置icon控件
nativeView.setIconView(icon);
nativeView.setMediaView(mediaView, ImageView.ScaleType.FIT_XY);
nativeView.setAdChoiceView(adChoicesView);
nativeView.setAdCloseView(adCloseView);
// Mandatory: Set app store logo control
nativeView.setPsMarkView(storeMarkView);
// Mandatory: Set Russian Compliant Version AD Badge
nativeView.setAdBagdeView(adBadgeView);
// Mandatory: Set Russian Compliant Version Disclaimer
nativeView.setAdDisclaimerView(adDisclaimerView);
// Add ad view
nativeView.addView(adView);
title.setText(adNativeInfo.getTitle());
des.setText(adNativeInfo.getDescription());
calltoaction.setText(adNativeInfo.getCtatext());
if (!TextUtils.isEmpty(adNativeInfo.getRating())) {
rating.setText("R : " + adNativeInfo.getRating());
}
List<View> adContains = new ArrayList<>();
adContains.add(title);
adContains.add(icon);
adContains.add(mediaView);
adContains.add(calltoaction);
adContains.add(des);
adContains.add(adView);
adContains.add(adCloseView);
adContains.add(storeMarkView);
nativeView.setupViews(adNativeInfo);
tNativeAd.registerViews(nativeView, adContains, adNativeInfo);
}
Reminder: Regarding Icon ads, the general approach is to set the icon and call to action. Please set them according to your specific requirements.
Template Rendering
private void inflateView(TaNativeInfo adNativeInfo, TNative nativeAd, TNativeView nativeView) {
// Template object
TemplateStyle templateStyle;
// Boolean类型:"isChangeStyle"
if (isChangeStyle) {
// Fine-tune the module as needed
templateStyle = new TemplateStyle.Builder()
.titleSize(20).titleColor(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_0051E1)).isTitleBold(0)
.descColor(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_0051E1)).descSize(20).isDescBold(1)
.callToAction_text_color(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_0051E1)).callToAction_text_isBold(1).callToAction_text_size(20)
.callToAction_background_color(CoreUtil.getContext().getResources().getColor(R.color.ad_button_bg_color))
.callToAction_corner_radius(0).callToAction_stroke_color(CoreUtil.getContext().getResources()
}.getColor(R.color.hisavana_ad_color_0051E1)).callToAction_stroke_width(5)
//.callToAction_background_shape(CoreUtil.getContext().getResources().getDrawable(R.drawable.hisavana_bg_shadow))
.background(CoreUtil.getContext().getResources().getColor(R.color.hisavana_ad_color_787878))
.build();
} else {
// Use the default template
templateStyle = new TemplateStyle.Builder().build();
}
nativeView.setTemplateStyle(templateStyle);
nativeAd.registerViews(nativeView, adNativeInfo);
}
Media Configuration Platform Settings
