الانتقال إلى وحدة التحكم

PublisherAdView

public final class PublisherAdView extends ViewGroup

The View to display banner ads for use with DoubleClick for Publishers (DFP). The ad size and ad unit ID must be set prior to calling loadAd(PublisherAdRequest).

Sample code:

 public class MyActivity extends Activity {
     private PublisherAdView mPublisherAdView;

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

         // Create an ad request.
         PublisherAdRequest.Builder publisherAdRequestBuilder = new PublisherAdRequest.Builder();

         // Optionally populate the ad request builder.
         publisherAdRequestBuilder.addTestDevice(PublisherAdRequest.DEVICE_ID_EMULATOR);

         // Add the PublisherAdView to the view hierarchy.
         layout.addView(mPublisherAdView);

         // Start loading the ad.
         mPublisherAdView.loadAd(PublisherAdRequestBuilder.build());

         setContentView(layout);
     }

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

         // Resume the PublisherAdView.
         mPublisherAdView.resume();
     }

     @Override
     public void onPause() {
         // Pause the PublisherAdView.
         mPublisherAdView.pause();

         super.onPause();
     }

     @Override
     public void onDestroy() {
         // Destroy the PublisherAdView.
         mPublisherAdView.destroy();

         super.onDestroy();
     }
 }

XML Attribute Summary

Inherited Constant Summary