Pour discuter de nos produits et nous faire part de vos commentaires, rejoignez le canal Discord officiel Ad Manager sur le serveur de la communauté Google Advertising and Measurement.
Les paramètres de style natif permettent à Google Ad Manager de gérer l'affichage de vos annonces natives en fonction des styles natifs que vous spécifiez dans le produit. Commencez par spécifier la taille et le ciblage.
Ajoutez ensuite du code HTML, CSS et JavaScript pour définir des annonces responsives qui s'affichent correctement sur tous les écrans. Vous n'avez pas besoin de vous occuper du rendu. Ad Manager applique automatiquement le style natif approprié à la destination. Les styles natifs sont implémentés de la même manière que les bannières publicitaires. Elles sont affichées avec une taille d'annonce fluide déterminée au moment de l'exécution ou avec une taille d'annonce fixe déterminée à l'avance.
Vous pouvez utiliser la taille d'annonce "Fluide" dans l'UI Ad Manager pour créer une annonce qui s'adapte dynamiquement à son contenu. Avec ce paramètre, la largeur de l'annonce correspondra au contenu de votre application, et sa hauteur s'ajustera au moment de l'exécution pour s'adapter au contenu de l'annonce. Le SDK fournit une constante spéciale AdSize, FLUID, pour gérer ce cas. La hauteur de l'annonce fluide est déterminée de manière dynamique en fonction de la largeur définie par l'éditeur, ce qui permet à la vue de l'annonce d'ajuster sa hauteur à celle de la création.
Créer une demande d'annonce fluide
Contrairement aux autres formats d'annonce, la taille d'annonce fluide n'a pas de largeur prédéfinie. Veillez donc à définir explicitement la layout_width de AdManagerAdView dans votre fichier de mise en page XML :
Voici à quoi ressemble l'implémentation pour effectuer la demande d'annonce :
Java
// fluidAdContainer is a ViewGroup that will be used to display the fluid native ad.AdManagerAdViewadView=(AdManagerAdView)fluidAdContainer;AdManagerAdRequestrequest=newAdManagerAdRequest.Builder().build();adView.loadAd(request);
// fluidAdContainer is a ViewGroup that will be used to display the fluid native ad.valadView=fluidAdContainerasAdManagerAdViewvalrequest=AdManagerAdRequest.Builder().build()adView.loadAd(request)
Les styles natifs de taille fixe vous permettent de contrôler la largeur et la hauteur de l'annonce native. Pour définir une taille fixe, procédez comme suit :
Créez un élément de campagne dans l'UI Ad Manager et sélectionnez l'une des tailles prédéfinies dans le menu déroulant du champ Size.
Dans le fichier de mise en page XML de votre application, définissez l'attribut ads:adSize sur la constante correspondant à la taille prédéfinie que vous avez sélectionnée à l'étape 1.
Vous pouvez consulter la liste des tailles et des constantes AdSize correspondantes dans la section Taille fixe.
Voici un exemple de spécification d'une taille fixe, telle que la taille d'annonce MEDIUM_RECTANGLE (300 x 250), dans votre fichier de mise en page :
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/31 (UTC).
[null,null,["Dernière mise à jour le 2025/08/31 (UTC)."],[[["\u003cp\u003eNative style settings in Google Ad Manager allow you to customize the look and feel of your native ads using HTML, CSS, and JavaScript for a seamless user experience.\u003c/p\u003e\n"],["\u003cp\u003eYou can define native ads with fixed dimensions, like traditional banners, or opt for fluid sizes that adjust dynamically to the available screen space.\u003c/p\u003e\n"],["\u003cp\u003eFluid size ads are ideal when you want the ad width to match your content but need the height to automatically adapt to the ad creative.\u003c/p\u003e\n"],["\u003cp\u003eTo implement native styles, you'll utilize the \u003ccode\u003eAdManagerAdView\u003c/code\u003e component and specify the desired size in your app's layout file, similar to banner ads.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Mobile Ads SDK 8.1 or higher is required to leverage native style settings for your ad units.\u003c/p\u003e\n"]]],["Native styles in Google Ad Manager use HTML, CSS, and JavaScript to define responsive ads. To implement, use `AdManagerAdView`, similar to banner ads. Specify fixed sizes by creating a line item in the UI and selecting a predefined size. Set the `ads:adSize` attribute in the app's XML layout to the matching constant. Fluid sizes, determined at runtime, require setting \"Fluid\" in the UI and using the `FLUID` constant with a specified `layout_width`. Use Mobile Ads SDK version 8.1 or higher.\n"],null,["Select platform: [Android](/ad-manager/mobile-ads-sdk/android/native/styles \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/native/styles \"View this page for the iOS platform docs.\") [Flutter](/ad-manager/mobile-ads-sdk/flutter/native/styles \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\n[Native style settings](//support.google.com/admanager/answer/6366914) let\nGoogle Ad Manager handle the rendering of your native ads based on\nnative styles you specify within the product. First, specify size and targeting.\nThen add HTML, CSS, and JavaScript to define ads that are responsive\nand produce a quality display across all screens. You don't need to do\nany of the rendering; Ad Manager automatically applies the right native style\nfor the destination. Native styles are implemented just like banner ads. They\nare rendered with a fluid ad size determined at runtime, or with a fixed\nad size determined ahead of time.\n\nPrerequisites\n\n- Complete the [Get started guide](/ad-manager/mobile-ads-sdk/android/quick-start).\n\nFluid size\n\nYou can use the Fluid ad size in the Ad Manager UI to achieve an ad that\ndynamically adjusts to fit its content. With this setting, the ad's width will\nmatch your app's content, and its height will adjust at runtime to accommodate\nthe ad's content. The SDK provides a special `AdSize` constant,\n[`FLUID`](/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/AdSize#FLUID()), to handle this case. The fluid ad size\nheight is dynamically determined based on the publisher defined width, allowing\nthe ad view to adjust its height to match that of the creative.\n\nCreate a fluid ad request\n\nUnlike other ad formats, the fluid ad size doesn't have a predefined width,\nso make sure to explicitly set the `layout_width` of the `AdManagerAdView`\nin your XML layout file: \n\n \u003ccom.google.android.gms.ads.admanager.AdManagerAdView\n android:id=\"@+id/fluid_ad_container\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"wrap_content\"\n android:layout_gravity=\"center_horizontal\"\n ads:adSize=\"FLUID\"\n ads:adUnitId=\"YOUR_AD_UNIT_ID\" /\u003e\n\n| **Note:** If you specify `wrap_content` for the `layout_width`, the `AdManagerAdView` width defaults to the width of its parent.\n\nHere's what the implementation looks like for making the ad request: \n\nJava \n\n // fluidAdContainer is a ViewGroup that will be used to display the fluid native ad.\n AdManagerAdView adView = (AdManagerAdView) fluidAdContainer;\n AdManagerAdRequest request = new AdManagerAdRequest.Builder().build();\n adView.loadAd(request); \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeStylesSnippets.java#L28-L31\n\nKotlin \n\n // fluidAdContainer is a ViewGroup that will be used to display the fluid native ad.\n val adView = fluidAdContainer as AdManagerAdView\n val request = AdManagerAdRequest.Builder().build()\n adView.loadAd(request) \n https://github.com/googleads/googleads-mobile-android-examples/blob/ccc290a583d7f552bdcf81ea76adc05beaa43f0b/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/NativeStylesSnippets.kt#L28-L31\n\n\u003cbr /\u003e\n\nFixed size\n\nNative styles with a fixed size allow you to control the width and height\nof the native ad. To set a fixed size, follow these steps:\n\n1. Create a line item in the Ad Manager UI and select one of the\n predefined sizes from the `Size` field drop-down.\n\n2. In your app's XML layout file, set the `ads:adSize` attribute to\n the constant that matches the predefined size you selected in step 1.\n You can see a list of sizes and their corresponding `AdSize` constants\n in the [Fixed size](/ad-manager/mobile-ads-sdk/android/banner/fixed_size)\n section.\n\nHere's an example of how to specify a fixed size, such as the\n`MEDIUM_RECTANGLE` (300x250) ad size, in your layout file: \n\n \u003ccom.google.android.gms.ads.admanager.AdManagerAdView\n android:id=\"@+id/ad_view_container\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:layout_gravity=\"center_horizontal\"\n ads:adSize=\"MEDIUM_RECTANGLE\"\n ads:adUnitId=\"YOUR_AD_UNIT_ID\" /\u003e\n\n\u003cbr /\u003e"]]