콘솔로 이동

SearchAdView

public final class SearchAdView extends ViewGroup

The View to display search banner ads for use with Search Ads for Apps. The ad size and ad unit ID must be set prior to calling loadAd(DynamicHeightSearchAdRequest).

Sample code:

 public class MyActivity extends Activity {
     private SearchAdView mSearchAdView;

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

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

         // Create a search ad. The ad size and ad unit ID must be set before calling loadAd.
         mSearchAdView = new SearchAdView(this);
         mSearchAdView.setAdSize(AdSize.SEARCH);
         mSearchAdView.setAdUnitId("myAdUnitId");

         // Create an ad request.
         DynamicHeightSearchAdRequest.Builder builder =
             new DynamicHeightSearchAdRequest.Builder();

         // Set the query.
         builder.setQuery("flowers");

         // Optionally populate the ad request builder.
         builder.setAdTest(true);
         builder.setNumber(2);
         builder.setCssWidth(300);     // Equivalent to "width" CSA parameter.

         // Add the SearchAdView to the view hierarchy.
         layout.addView(mSearchAdView);

         // Start loading the ad.
         mSearchAdView.loadAd(builder.build());

         setContentView(layout);
     }

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

         // Resume the SearchAdView.
         mSearchAdView.resume();
     }

     @Override
     public void onPause() {
         // Pause the SearchAdView.
         mSearchAdView.pause();

         super.onPause();
     }

     @Override
     public void onDestroy() {
         // Destroy the SearchAdView.
         mSearchAdView.destroy();

         super.onDestroy();
     }
 }

XML Attribute Summary

Inherited Constant Summary

Inherited Field Summary