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

AdManagerAdView

public final class AdManagerAdView extends ViewGroup

The View to display banner ads for use with Google Ad Manager. The ad size and ad unit ID must be set prior to calling loadAd(AdManagerAdRequest).

Sample code:

 public class MyActivity extends Activity {
     private AdManagerAdView adManagerAdView;

     @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.
         adManagerAdView = new AdManagerAdView(this);
         adManagerAdView.setAdSize(AdSize.SMART_BANNER);
         adManagerAdView.setAdUnitId("myAdUnitId");

         // Add the AdManagerAdView to the view hierarchy.
         layout.addView(adManagerAdView);

         // Start loading the ad.
         adManagerAdView.loadAd(new AdManagerAdRequest.Builder().build());

         setContentView(layout);
     }

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

         // Resume the AdManagerAdView.
         adManagerAdView.resume();
     }

     @Override
     public void onPause() {
         // Pause the AdManagerAdView.
         adManagerAdView.pause();

         super.onPause();
     }

     @Override
     public void onDestroy() {
         // Destroy the AdManagerAdView.
         adManagerAdView.destroy();

         super.onDestroy();
     }
 }

XML Attribute Summary

Inherited Constant Summary

Inherited Field Summary

Public Constructor Summary

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

Public Method Summary

void
destroy()
Destroys the AdManagerAdView.
AdListener
AdSize
getAdSize()
Returns the size of the currently displayed banner ad.
AdSize[]
getAdSizes()
Returns the ad sizes supported by this AdManagerAdView.
String
getAdUnitId()
Returns the ad unit ID.
AppEventListener
ResponseInfo
getResponseInfo()
Returns the ResponseInfo object for the loaded ad.
VideoController
getVideoController()
Returns the VideoController for this ad view.
VideoOptions
getVideoOptions()
Returns the VideoOptions for this ad view.
boolean
isLoading()
Returns true if the ad is loading.
void
loadAd(AdManagerAdRequest adManagerAdRequest)
Loads an ad.
void
pause()
Pauses any extra processing associated with this AdManagerAdView.
void
recordManualImpression()
Records a manual impression.
void
resume()
Resumes an AdManagerAdView after a previous call to pause().
void
void
setAdSizes(AdSize... adSizes)
Sets the supported sizes of the banner ad.
void
setAdUnitId(String adUnitId)
Sets the ad unit ID.
void
void
setManualImpressionsEnabled(boolean manualImpressionsEnabled)
Indicates whether you intend to record impressions manually for this AdManagerAdView.
void
setVideoOptions(VideoOptions videoOptions)
Sets the VideoOptions for this ad view.

Protected Method Summary

void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Inherited Method Summary