Menaka
Menaka

Reputation: 13

Admob ads for multiple activites via XML

Hello I'm new to Admob I have successfully added admob into my Main activity XML via below code provided by google, but the thing is my ad only contains on Main activity.. so i planned to paste same code into other activities as well.. is that right method ? or there is another way to do that only with XML not Java..

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>

Thanks

Upvotes: 0

Views: 463

Answers (1)

Eefret
Eefret

Reputation: 4774

You can create a separate layout called ad_view.xml or so and include it in your other layouts with the include tag, something like this:

ad_view.xml

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>

your other layouts

<include
        layout="@layout/ad_view"
        android:id="@+id/ad_View"/>

Note that in the include you can override multiple properties of your layout its very usefull. Hope it helps you out, good luck.

Upvotes: 2

Related Questions