Native Styles

Native style settings enable Google Ad Manager to handle the rendering of your native ads based on native styles you specify within the product. First, specify size and targeting. Then add HTML, CSS, and JavaScript to define ads that are responsive and produce a quality display across all screens. You don't need to do any of the rendering; Ad Manager automatically applies the right native style for the destination. Native styles are implemented just like banner ads, using a AdManagerAdView. They can be used with a fixed ad size determined ahead of time, or a fluid ad size determined at runtime.

Prerequisites

  • Google Mobile Ads SDK version 8.1 or higher

This guide assumes some working knowledge of the Google Mobile Ads SDK. If you haven't already done so, consider running through our Get Started guide.

Fixed size

Native styles with a fixed size allow you to control the width and height of the native ad. To set a fixed size, follow these steps:

  1. Create a line item in the Ad Manager UI and select one of the predefined sizes from the Size field dropdown.

  2. In your app's XML layout file, set the ads:adSize attribute to the constant that matches the predefined size you selected in step 1. You can see a list of sizes and their corresponding AdSize constants in the Banner size section.

Here's an example of how to specify a fixed size, such as the MEDIUM_RECTANGLE (300x250) ad size, in your layout file:

<com.google.android.gms.ads.admanager.AdManagerAdView
   android:id="@+id/fluid_view"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center_horizontal"
   ads:adSize="MEDIUM_RECTANGLE"
   ads:adUnitId="YOUR_AD_UNIT_ID" />

Fluid size

In some cases, a fixed size may not make sense. For example, you may want the width of the ad to match your app's content, but need its height to dynamically adjust to fit the ad's content. To handle this case, you can specify Fluid as the ad size in the Ad Manager UI, which designates that the size of the ad is determined at runtime in the app. The SDK provides a special AdSize constant, FLUID, to handle this case. The fluid ad size height is dynamically determined based on the publisher defined width, allowing the AdManagerAdView to adjust its height to match that of the creative.

Fluid request

Unlike other ad formats, the fluid ad size doesn't have a predefined width, so make sure to explicitly set the layout_width of the AdManagerAdView in your XML layout file:

<com.google.android.gms.ads.admanager.AdManagerAdView
   android:id="@+id/fluid_view"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_gravity="center_horizontal"
   ads:adSize="FLUID"
   ads:adUnitId="YOUR_AD_UNIT_ID" />

Here's what the implementation looks like for making the ad request:

private AdManagerAdView mAdView;

@Override
public void onActivityCreated(Bundle savedInstanceState) {
   super.onActivityCreated(savedInstanceState);
   mAdView = (AdManagerAdView) getView().findViewById(R.id.fluid_view);
   AdManagerAdRequest request = new AdManagerAdRequest.Builder().build();
   mAdView.loadAd(request);
}

To see an example implementation of the Ad Manager Fluid ad size, download the Android API Demo app:

Download API Demo