Banner Ads

The following block of code creates and loads a banner ad:

In your layout:


In your activity or fragment:

public class MainActivity extends Activity {

    // define a SABannerAd
    private SABannerAd bannerAd = null;

    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.activity_main);

        // get the banner from the layout
        bannerAd = (SABannerAd) findViewById (;

        // to display test ads
        bannerAd.enableTestMode ();

        // set configuration to production
        bannerAd.setConfigurationProduction ();

        // set background color as transparent
        bannerAd.setColorTransparent ();

        // start loading ad data for a placement
        bannerAd.load (30471);

Once you’ve loaded an ad, you can also display it:

public void onClick (View view) {

    // check if ad is loaded
    if (bannerAd.hasAdAvailable ()) {

        // display the ad (MainActivity.this);

These are the default values:

Parameter Value
Configuration Production
Test mode Disabled
Background Gray