Google is committed to advancing racial equity for Black communities. See how.

AdView

public final class AdView extends BaseAdView

The View to display banner ads. The ad size and ad unit ID must be set prior to calling BaseAdView.loadAd(AdRequest).

Publishers using Ad Manager or Search Ads for Apps should use AdManagerAdView or SearchAdView, respectively.

Sample code:

 public class MyActivity extends Activity {
     private AdView mAdView;

     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         LinearLayout layout = new LinearLayout(this);
         layout.setOrientation(LinearLayout.VERTICAL);

         // Create a banner ad. The ad size and ad unit ID must be set before calling loadAd.
         mAdView = new AdView(this);
         mAdView.setAdSize(AdSize.SMART_BANNER);
         mAdView.setAdUnitId("myAdUnitId");

         // Create an ad request.
         AdRequest.Builder adRequestBuilder = new AdRequest.Builder();

         // Add the AdView to the view hierarchy.
         layout.addView(mAdView);

         // Start loading the ad.
         mAdView.loadAd(adRequestBuilder.build());

         setContentView(layout);
     }

     @Override
     public void onResume() {
         super.onResume();

         // Resume the AdView.
         mAdView.resume();
     }

     @Override
     public void onPause() {
         // Pause the AdView.
         mAdView.pause();

         super.onPause();
     }

     @Override
     public void onDestroy() {
         // Destroy the AdView.
         mAdView.destroy();

         super.onDestroy();
     }
 }

XML Attribute Summary

Inherited XML Attribute Summary

Inherited Constant Summary

Inherited Field Summary

Public Constructor Summary

AdView(Context context)
Constructs an AdView from code.
AdView(Context context, AttributeSet attrs)
Constructs an AdView from an XML layout.
AdView(Context context, AttributeSet attrs, int defStyle)
Constructs an AdView from an XML layout.

Inherited Method Summary

XML Attributes

AdsAttrs_adSize

    AdsAttrs_adUnitId

      Public Constructors

      public AdView (Context context)

      Constructs an AdView from code.

      Parameters
      context The Context the AdView is running in.

      public AdView (Context context, AttributeSet attrs)

      Constructs an AdView from an XML layout.

      public AdView (Context context, AttributeSet attrs, int defStyle)

      Constructs an AdView from an XML layout.

      Attribute Name
      AdsAttrs_adSize
      AdsAttrs_adUnitId