Banner
A rectangular ad that can be fixed to the top or bottom of the screen.
Introduction
The image at the top, middle or bottom of the App. Please refer to the ad source Hisavana for supported ad sizes: 20:3, 3:2. The effect is as follows:
20:3 | 3:2 |
---|---|
![]() | ![]() |
Build Components
Create a TBannerView object.
// Please add TBannerView in the xml of the parent layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e8e8e8"
android:orientation="vertical">
<com.hisavana.mediation.ad.TBannerView
android:id="@+id/banner_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:visibility="gone"/>
</RelativeLayout>
// Bind views in xml layout
TBannerView tBannerView = findViewById(R.id.banner_view);
or
// Manually create a TBannerView object and "add it to the parent layout"
TBannerView tBannerView = new TBannerView(this);
Load Ads
Please set the corresponding parameters and listening callbacks.
// Set the banner size (not applicable to Yandex), please refer to "Size and Type" below
tBannerView.setAdSize(BannerSize.SIZE_320x50);
// Optional. If you connect to "Yandex", please set the width first. The default screen width (only supports Yandex adaptive stickiness, unit: dp)
// tBannerView.setAdWidth(300);
// Optional. If you need to connect to admob folding banner, please set this property. For other types, please refer to "Size and Type" below
// tBannerView.setBannerType(IBannerType.BANNER_TYPE_TOP_FOLD);
// "banner_id" is the Banner ad slot ID
tBannerView.setAdUnitId("banner_id");
/**
* Optional
* For applications that need to count the arrival of advertising scenes, you can set the scene value yourself.
* The main purpose is to count the utilization rate of the current advertising scene. The first parameter is the custom scene name, and the second parameter is the number of advertisements.
*/
tBannerView.enterScene("banner_scene_name", 1);
// Construct ad request body
TAdRequestBody tAdRequest = new TAdRequestBody.AdRequestBodyBuild()
.setAdListener(new TAdAlliance())
.build();
// Set ad request body
tBannerView.setRequestBody(tAdRequest);
// After loading the advertisement, the optimal advertisement callback will be returned within the set waiting time.
tBannerView.loadAd();
// Ad listener, listens for callbacks of ad loading completion (filling), display, click, exception, and closing actions
private static class TAdAlliance extends TAdListener {
// Loading completion callback (applicable ad slots: all ad slots)
@Override
public void onLoad() {
// Ad loaded callback
}
// Abnormal callback (applicable ad slots: all ad slots)
@Override
public void onError(TAdErrorCode errorCode) {
// Ad failed callback
}
// Display callback (applicable ad slots: Splash, Interstitial, Banner, Reward)
@Override
public void onShow(int source) {
// Ad show callback
}
// Click callback (applicable ad slots: Splash, Interstitial, Banner, Reward)
@Override
public void onClicked(int source) {
// Ad click callback
}
// Close callback (applicable ad slots: Splash, Interstitial, Banner, Reward)
@Override
public void onClosed(int source) {
// Ad close callback
}
// Display failure callback (applicable ad slots: all ad slots)
@Override
public void onShowError(TAdErrorCode errorCode) {
// Ad show failed callback
}
}
Reminder: source represents the advertising source, please refer to Advertising Source Association Table; For example: this time the advertisement is filled with pangle ads, then source=6.
Display Ads
Please display the TBannerView object.
// Banner ads are automatically displayed after loading and filling. If the view is hidden, please check the view visibility. If the view is added dynamically, please check whether it has been added to the parent layout.
tBannerView.setVisibility(View.VISIBLE);
Destroy Ads
After exiting the advertising scene, please destroy the advertising object.
@Override
protected void onDestroy() {
super.onDestroy();
if (tBannerView != null) {
tBannerView.destroy();
tBannerView.removeAllViews();
removeView(tBannerView);
tBannerView = null;
}
}
// Remove ad view
private void removeView(View v) {
if (v == null) return;
ViewParent viewGroup = v.getParent();
if (viewGroup instanceof ViewGroup) {
((ViewGroup) viewGroup).removeView(v);
}
}
Other APIs
API call | Introduce |
---|---|
tBannerView.hasAd() | Are there any ads currently available |
tBannerView.resume() | Please call it in the life cycle |
tBannerView.pause() | Please call it in the life cycle |
Reminder: After adding the Mintergral advertising source, when the system's onResume and onPause are called, the media needs to actively call the above two life cycle callback methods, which can reduce the number of Mintergral advertising source errors.
Size and Type
TBannerView It is a placeholder view for Banner ads. The width and width must be at least larger than TAdBannerSize, otherwise errors will occur in ad display. When using admob's adaptivebanner, the Banner Size needs to be 320 * 50
Banner Size (applicable to non-Yandex)
BannerSize constant | Size dp (unit: dp) |
---|---|
SIZE_320x50 | 320*50 |
SIZE_320x90 | 320*90 |
SIZE_320x100 | 320*100 |
SIZE_320x250 | 320*250 |
Banner type (for Admob)
IBannerType constant | Banner Type |
---|---|
BANNER_TYPE_TOP_FOLD | Top folding banner ad |
BANNER_TYPE_BOTTOM_FOLD | Bottom folding banner ad |
BANNER_TYPE_NORMAL | Ordinary banner advertising |