[null,null,["上次更新時間:2025-08-25 (世界標準時間)。"],[[["\u003cp\u003eNative Templates offer pre-built ad views for faster implementation and easier customization of native ads, leading to a better user experience and potentially higher ad revenue.\u003c/p\u003e\n"],["\u003cp\u003eThese templates come in two sizes (small and medium), suitable for various placements within your app, such as in feeds or as standalone elements.\u003c/p\u003e\n"],["\u003cp\u003eYou can easily integrate Native Templates by importing the provided module into your Android Studio project and adding a dependency in your build.gradle file.\u003c/p\u003e\n"],["\u003cp\u003eStyling options include using the NativeTemplateStyle.Builder object or modifying the XML layouts directly to match your app's design.\u003c/p\u003e\n"],["\u003cp\u003eContributions to the Native Templates project are welcomed through pull requests on the GitHub repository.\u003c/p\u003e\n"]]],["Native Templates provide pre-built views for native ads, allowing for quick implementation and customization. Download the templates from GitHub and import the module into your Android Studio project. There are small and medium template sizes, both using the `TemplateView` class. To use, include the template in your layout XML and provide the native ad data using the `NativeTemplateStyle.Builder` to customize styling options such as colors and text. Contributions to the GitHub repository are welcomed.\n"],null,["# Native Templates\n\nSelect platform: [Android](/ad-manager/mobile-ads-sdk/android/native/templates \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/native/templates \"View this page for the iOS platform docs.\") [Flutter](/ad-manager/mobile-ads-sdk/flutter/native/templates \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\n[Download Native Templates](//github.com/googleads/googleads-mobile-android-native-templates)\n| **Key Point:** Before continuing, know how to [load a native\n| ad](/ad-manager/mobile-ads-sdk/android/native#load-ad).\n\n\nUsing native ads you can customize your ads resulting in a better user\nexperience. Better user experiences can increase engagement and improve your\noverall yield.\n\nIn order to get the most out of native ads, it's important to style your ad\nlayouts so that they feel like a natural extension of your app. To help you get\nstarted, we've created Native Templates.\n\nNative Templates are code-complete views for your native ads, designed for fast\nimplementation and easy modification. With Native Templates, you can implement\nyour first native ad in just a few minutes, and you can quickly customize the\nlook and feel without a lot of code. You can place these templates anywhere you\nwant, such as in a recycler view used in a news feed, in a dialog, or anywhere\nelse in your app.\n| **Note:** If you're interested in designing your own native layouts from scratch, return to the [Native Advanced](/ad-manager/mobile-ads-sdk/android/native/advanced) documentation instead.\n\nOur native templates are provided as an Android Studio module, so it's easy to\ninclude them in your project and use them however you like.\n\nTemplate sizes\n--------------\n\nThere are two templates: small and medium. They both use the `TemplateView`\nclass and both have a fixed aspect ratio. They will scale to fill the width of\ntheir parent views.\n\n### Small template\n\n @layout/gnt_small_template_view\n\nThe small template is ideal for recycler views, or any time you need a long\nrectangular ad view. For instance you could use it for in-feed ads.\n\n### Medium template\n\n @layout/gnt_medium_template_view\n\nThe medium template is meant to be a one-half to three-quarter page view but\ncan also be used in feeds. It is good for landing pages or splash pages.\n\nFeel free to experiment with placement. Of course, you can also change the\nsource code and XML files to suit your requirements.\n\nInstalling the native ad templates\n----------------------------------\n\nTo install the native templates, simply [download the zip file (using the\n**Clone or download** option on\nGitHub)](//github.com/googleads/googleads-mobile-android-native-templates) and\nimport the module into your existing Android Studio project.\n\n1. Choose **File \\\u003e New \\\u003e Import Module**.\n\n2. Select the `nativetemplates` folder.\n\n3. Add the following line to your app-level `build.gradle` file:\n\n dependencies {\n ...\n implementation project(':nativetemplates')\n ...\n }\n\nUsing the native ad templates\n-----------------------------\n\nYou can use the template in any layout XML file, like any other view\ngroup.\n\nUsing the templates is a two-step process:\n\n1. First, you need to include the template as part of your layout.\n\n \u003cLinearLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n xmlns:tools=\"http://schemas.android.com/tools\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\n tools:context=\".MainActivity\"\n tools:showIn=\"@layout/activity_main\" \u003e\n\n \u003c!-- This is your template view --\u003e\n \u003ccom.google.android.ads.nativetemplates.TemplateView\n android:id=\"@+id/my_template\"\n \u003c!-- this attribute determines which template is used. The other option is\n @layout/gnt_medium_template_view --\u003e\n app:gnt_template_type=\"@layout/gnt_small_template_view\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\" /\u003e\n\n ...\n \u003c/LinearLayout\u003e\n\n2. Next, you need to give your template your native ad when it loads:\n\n MobileAds.initialize(this);\n AdLoader adLoader = new AdLoader.Builder(this, \"/21775744923/example/native\")\n .forNativeAd(new NativeAd.OnNativeAdLoadedListener() {\n @Override\n public void onNativeAdLoaded(NativeAd nativeAd) {\n NativeTemplateStyle styles = new\n NativeTemplateStyle.Builder().withMainBackgroundColor(background).build();\n TemplateView template = findViewById(R.id.my_template);\n template.setStyles(styles);\n template.setNativeAd(nativeAd);\n }\n })\n .build();\n\n adLoader.loadAd(new AdManagerAdRequest.Builder().build());\n\nStyles dictionary keys\n----------------------\n\nThere are two ways to style your template: using traditional layout XML and\nusing our `NativeTemplateStyle.Builder` object. The above code sample\ndemonstrates how to use the `NativeTemplateStyle.Builder` object to set the main\nbackground color, but there are a variety of other options as well. Here are all\nof the available builder methods. The builder returns a `NativeTemplateStyle`\nobject which overrides any XML layout styling. The XML layouts\n`gnt_small_template.xml` and `gnt_medium_template.xml` use the same Android\nstyling parameters that you are already familiar with.\n\n| Builder methods for native template style ||\n|------------------------------------|----------------------------------------------------------------------------------------------|\n| `withCallToActionTextTypeface` | `Typeface callToActionTextTypeface` The typeface for the call to action. |\n| `withCallToActionTextSize` | `float callToActionTextSize` The size of the call to action text. |\n| `withCallToActionTypefaceColor` | `int callToActionTypefaceColor` The color of the call to action text. |\n| `withCallToActionBackgroundColor` | `ColorDrawable callToActionBackgroundColor` The background color of the call to action. |\n| `withPrimaryTextTypeface` | `Typeface primaryTextTypeface` The typeface of the first row of text. |\n| `withPrimaryTextSize` | `float primaryTextSize` The size of the first row of text. |\n| `withPrimaryTextTypefaceColor` | `int primaryTextTypefaceColor` The color of the first row of text. |\n| `withPrimaryTextBackgroundColor` | `ColorDrawable primaryTextBackgroundColor` The background color of the first row of text. |\n| `withSecondaryTextTypeface` | `Typeface secondaryTextTypeface` The typeface of the second row of text. |\n| `withSecondaryTextSize` | `float secondaryTextSize` The size of the second row of text. |\n| `withSecondaryTextTypefaceColor` | `int secondaryTextTypefaceColor` The text color of the second row of text. |\n| `withSecondaryTextBackgroundColor` | `ColorDrawable secondaryTextBackgroundColor` The background color of the second row of text. |\n| `withTertiaryTextTypeface` | `Typeface tertiaryTextTypeface` The typeface of the third row of text. |\n| `withTertiaryTextSize` | `float tertiaryTextSize` The size of the third row of text. |\n| `withTertiaryTextTypefaceColor` | `int tertiaryTextTypefaceColor` The text color of the third row of text. |\n| `withTertiaryTextBackgroundColor` | `ColorDrawable tertiaryTextBackgroundColor` The background color of the third row of text. |\n| `withMainBackgroundColor` | `ColorDrawable mainBackgroundColor` The main background color. |\n\nContribute\n----------\n\nWe've made Native Templates to help you develop native ads quickly.\nWe'd love to see you contribute to our\n[GitHub](//github.com/googleads/googleads-mobile-android-native-templates)\nrepo to add new templates or features. Send us a pull request and we'll take a\nlook."]]