Click here to see your recently viewed pages and most viewed pages.
Hide
AdMob Android Guides

Banner Ad Customization

Introduction

In the Quick Start 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.

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.

Back to top

Smart Banners

Smart Banners allow for the rendering of full width ads across different devices and orientations by "smartly" sizing ad units according to screen size. Three ad heights (in dp, density-independent pixel) are available:

  • 32 - phones in landscape
  • 50 - phones in portrait
  • 90 - tablets in either orientation

More specifically, if the screen height of a device is between 400 and 720, an ad height of 50 is used in both orientations; for screen heights greater than 720, a 90 ad height is used.

When an image ad won't take up the entire allotted space for the banner, we'll center the image and use a hexagonal textile filler (see image) to fill up the remaining space. Note that AdSense backfill ads will be centered and have "transparent" filler.

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

AdView adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);

Back to top

Ad lifecycle event callbacks

You may optionally track ad lifecycle events like request failures or "click-through" by passing an object to AdView.setAdListener that extends com.google.android.gms.ads.AdListener.

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() {
  @Override
  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:

  • AdRequest.ERROR_CODE_INTERNAL_ERROR
  • AdRequest.ERROR_CODE_INVALID_REQUEST
  • AdRequest.ERROR_CODE_NETWORK_ERROR
  • AdRequest.ERROR_CODE_NO_FILL
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 application after clicking on an ad.

public void onAdLeftApplication()

Called when an ad leaves the application (e.g., to go to the browser).

You can download an example project containing a sample AdListener here.

Back to top

What's next