Banner
Banner ads are classic static banners, usually located at the bottom or top of the screen. Appodeal supports traditional 320x50 banners, 728x90 tablet banners and smart banners that adjust to the size and orientation of the device.
You can use our demo banner app as a reference project.
Demo App
Fixed Positioned Banner
Display Banner At The Specific Position Of The Screen
To display banner, you need to call the following code in the activity:
- Kotlin
- Java
Appodeal.show(this, Appodeal.BANNER) // Display banner with last position or bottom position of the screen
Appodeal.show(this, Appodeal.BANNER_BOTTOM) // Display banner at the bottom of the screen
Appodeal.show(this, Appodeal.BANNER_TOP) // Display banner at the top of the screen
Appodeal.show(this, Appodeal.BANNER_LEFT) // Display banner at the left of the screen
Appodeal.show(this, Appodeal.BANNER_RIGHT) // Display banner at the right of the screen
Appodeal.show(this, Appodeal.BANNER); // Display banner with last position or bottom position of the screen
Appodeal.show(this, Appodeal.BANNER_BOTTOM); // Display banner at the bottom of the screen
Appodeal.show(this, Appodeal.BANNER_TOP); // Display banner at the top of the screen
Appodeal.show(this, Appodeal.BANNER_LEFT); // Display banner at the left of the screen
Appodeal.show(this, Appodeal.BANNER_RIGHT); // Display banner at the right of the screen
The method returns a boolean value indicating whether the call to the show method was passed to the appropriate SDK.
BannerView
should be on the top of the hierarchy and can not be overlapped by other views.Check If Ad Is Loaded
You can check if the ad has been loaded before showing it. This method returns a boolean value indicating whether or not the banner has been loaded.
- Kotlin
- Java
Appodeal.isLoaded(Appodeal.BANNER)
Appodeal.isLoaded(Appodeal.BANNER);
Manual Caching
By default, auto caching is enabled: Appodeal SDK starts to load Banner right after the initialization method is called.
The next banner ad starts to load after the previous one has been closed.
To disable automatic caching for banner, use the code below before SDK initialization:
- Kotlin
- Java
Appodeal.setAutoCache(Appodeal.BANNER, false)
Appodeal.setAutoCache(Appodeal.BANNER, false);
To cache banner use:
- Kotlin
- Java
Appodeal.cache(this, Appodeal.BANNER)
Appodeal.cache(this, Appodeal.BANNER);
Read more on manual caching in our FAQ.
Hide
- Kotlin
- Java
Appodeal.hide(this, Appodeal.BANNER)
Appodeal.hide(this, Appodeal.BANNER);
Callbacks
- Kotlin
- Java
Appodeal.setBannerCallbacks(object : BannerCallbacks {
override fun onBannerLoaded(height: Int, isPrecache: Boolean) {
// Called when banner is loaded
}
override fun onBannerFailedToLoad() {
// Called when banner failed to load
}
override fun onBannerShown() {
// Called when banner is shown
}
override fun onBannerShowFailed() {
// Called when banner show failed
}
override fun onBannerClicked() {
// Called when banner is clicked
}
override fun onBannerExpired() {
// Called when banner is expired
}
})
Appodeal.setBannerCallbacks(new BannerCallbacks() {
@Override
public void onBannerLoaded(int height, boolean isPrecache) {
// Called when banner is loaded
}
@Override
public void onBannerFailedToLoad() {
// Called when banner failed to load
}
@Override
public void onBannerShown() {
// Called when banner is shown
}
@Override
public void onBannerShowFailed() {
// Called when banner show failed
}
@Override
public void onBannerClicked() {
// Called when banner is clicked
}
@Override
public void onBannerExpired() {
// Called when banner is expired
}
});
All callbacks are called on the main thread.
Custom Positioned Banner
Display Banner In The Specified View In The Layout File
- Add
com.appodeal.ads.BannerView
to your layout file:
<com.appodeal.ads.BannerView
android:id="@+id/appodealBannerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
- Set view id before the SDK initialization to show banner:
- Kotlin
- Java
Appodeal.setBannerViewId(R.id.appodealBannerView)
Appodeal.setBannerViewId(R.id.appodealBannerView);
- Now you can show the banner in the view specified (Make sure that the required view is on the screen):
- Kotlin
- Java
Appodeal.show(this, Appodeal.BANNER_VIEW)
Appodeal.show(this, Appodeal.BANNER_VIEW);
BannerView
should be on the top of the hierarchy and can not be overlapped by other views.