0

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

Menaka
  • 13
  • 2
  • Either extend a custom activity class (see [this](http://stackoverflow.com/questions/10234762/admob-on-multiple-activities) ) or make a separate layout for your admob banner and include it on every layout. – Kunu Apr 29 '15 at 16:58

1 Answers1

2

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.

Eefret
  • 4,724
  • 4
  • 30
  • 46