Banner Ads

In the Get Started in Android Studio guide, you learned how to deploy the SDK and display a test banner ad. This guide goes into further customizations that are possible with banner ads.

To see implementations of these banner ad customizations, download the Android API Demo app.

Download API demo

The following ad formats are supported:

Size (WxH) Description Availability AdSize constant
320x50 Standard Banner Phones and Tablets BANNER
320x100 Large Banner Phones and Tablets LARGE_BANNER
300x250 IAB Medium Rectangle Phones and Tablets MEDIUM_RECTANGLE
468x60 IAB Full-Size Banner Tablets FULL_BANNER
728x90 IAB Leaderboard Tablets LEADERBOARD
Screen width x 32|50|90 Smart Banner Phones and Tablets SMART_BANNER

The SDK will request whatever size the requesting AdView was instantiated with. If there isn't enough space on the device's screen to display the ad, nothing will be shown.

Smart Banners

Smart Banners are ad units that render screen-width banner ads on any screen size across different devices in either orientation. Smart Banners help deal with increasing screen fragmentation across different devices by "smartly" detecting the width of the phone in its current orientation and making the ad view that size.

Three ad heights (in density-independent pixels [dp]) are implemented in smart banners:

Ad height Screen height
32dp ≤400dp
50dp > 400dp and ≤ 720dp
90dp > 720dp

For some devices, such as phones, the height of the device varies with its orientation. Typically, Smart Banners on phones are full width x 50dp in portrait and full width x 32dp in landscape; while on tablets, ads are full width x 90dp in both orientations.

When an image ad isn't large enough to take up the entire allotted space, the image will be centered, and the space on either side will be filled in.

To use Smart Banners, specify the constant SMART_BANNER for the ad size:

AdView adView = new AdView(this);

See the AdMob banner sizes example for an implementation of Smart Banners in the Android API Demo app.

Ad lifecycle event callbacks

You may optionally track ad lifecycle events like request failures or "clickthrough" by passing an object to AdView.setAdListener() that extends

public abstract class AdListener {
    public void onAdLoaded();
    public void onAdFailedToLoad(int errorCode);
    public void onAdOpened();
    public void onAdClosed();
    public void onAdLeftApplication();

A separate class extending AdListener may be defined, or you can choose to inline an AdListener object:

adView.setAdListener(new AdListener() {
    public void onAdOpened() {
        // Save app state before going to the ad overlay.

AdListener provides a default empty implementation for all of its ad lifecycle events. You only need to override the ad events you wish to implement.

public void onAdLoaded()
Called when an ad is received.
public void onAdFailedToLoad(int errorCode)

Called when an ad request failed. The error code is usually one of the following:

public void onAdOpened()

Called when an ad opens an overlay that covers the screen.

public void onAdClosed()

Called when the user is about to return to the app after clicking on an ad.

public void onAdLeftApplication()

Called when an ad leaves the app (for example, to go to the browser).

See the AdMob AdListener example for an implementation of ad lifecycle event callbacks in the Android API Demo app.

Next steps

  • Learn how best to implement banner ads in a compliant manner in the Banner ad guidance in the Help Center.
  • Learn about full-screen interstitial ads in the Interstitial Ads guide.
  • Explore targeting capabilities of banner ads in the Targeting guide.

Send feedback about...

AdMob by Google
AdMob by Google