Style ad layouts with native templates

  • Native Templates provide code-complete views for native ads, enabling fast implementation and easy modification to seamlessly integrate ads into your app's design.

  • There are two template sizes available, small and medium, both using the TemplateView class and scaling to fill the width of their parent views.

  • Installing the templates involves downloading the module from GitHub and importing it into your Android Studio project.

  • Using the templates requires including the template in your layout XML and then setting the loaded native ad on the template view.

  • You can style the templates using either traditional layout XML or the NativeTemplateStyle.Builder object, which offers various customization options for text and background elements.

Download Native Templates

Using native ads you can customize your ads resulting in a better user experience. Better user experiences can increase engagement and improve your overall yield.

In order to get the most out of native ads, it's important to style your ad layouts so that they feel like a natural extension of your app. To help you get started, we've created Native Templates.

Native Templates are code-complete views for your native ads, designed for fast implementation and easy modification. With Native Templates, you can implement your first native ad in just a few minutes, and you can quickly customize the look and feel without a lot of code. You can place these templates anywhere you want, such as in a recycler view used in a news feed, in a dialog, or anywhere else in your app.

Our native templates are provided as an Android Studio module, so it's easy to include them in your project and use them however you like.

Template sizes

There are two templates: small and medium. They both use the TemplateView class and both have a fixed aspect ratio. They will scale to fill the width of their parent views.

Small template

@layout/gnt_small_template_view

The small template is ideal for recycler views, or any time you need a long rectangular ad view. For instance you could use it for in-feed ads.

Medium template

@layout/gnt_medium_template_view

The medium template is meant to be a one-half to three-quarter page view but can also be used in feeds. It is good for landing pages or splash pages.

Feel free to experiment with placement. Of course, you can also change the source code and XML files to suit your requirements.

Installing the native ad templates

To install the native templates, simply download the zip file (using the Clone or download option on GitHub) and import the module into your existing Android Studio project.

  1. Choose File > New > Import Module.

  2. Select the nativetemplates folder.

    import native template

  3. Add the following line to your app-level build.gradle file:

    dependencies {
            ...
            implementation project(':nativetemplates')
            ...
    }
    

Using the native ad templates

You can use the template in any layout XML file, like any other view group.

add template to layout

Using the templates is a two-step process:

  1. First, you need to include the template as part of your layout.

    <LinearLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       xmlns:tools="http://schemas.android.com/tools"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       tools:context=".MainActivity"
       tools:showIn="@layout/activity_main" >
    
    <!--  This is your template view -->
    <com.google.android.ads.nativetemplates.TemplateView
       android:id="@+id/my_template"
       <!-- this attribute determines which template is used. The other option is
        @layout/gnt_medium_template_view -->
       app:gnt_template_type="@layout/gnt_small_template_view"
       android:layout_width="match_parent"
       android:layout_height="match_parent" />