Native styles

Select platform: Android iOS Flutter

Native style settings let Google Ad Manager 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. They are rendered with a fluid ad size determined at runtime, or with a fixed ad size determined ahead of time.

Prerequisites

Fluid size

You can use the Fluid ad size in the Ad Manager UI to achieve an ad that dynamically adjusts to fit its content. With this setting, the ad's width will match your app's content, and its height will adjust at runtime to accommodate the ad's content. 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 ad view to adjust its height to match that of the creative.

Create a fluid ad 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_ad_container"
   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:

Java

// fluidAdContainer is a ViewGroup that will be used to display the fluid native ad.
AdManagerAdView adView = (AdManagerAdView) fluidAdContainer;
AdManagerAdRequest request = new AdManagerAdRequest.Builder().build();
adView.loadAd(request);

Kotlin

// fluidAdContainer is a ViewGroup that will be used to display the fluid native ad.
val adView = fluidAdContainer as AdManagerAdView
val request = AdManagerAdRequest.Builder().build()
adView.loadAd(request)

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 drop-down.

  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 Fixed 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/ad_view_container"
   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" />