1

I have a situation where i would like to disable an Adview and prefer from xml. The adview itself looks like this in my layout file:

  <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-12345678934343/85666666">

How can i disable this ? one way is to wrap it around a linearlayout and then hide that layout but i want to disable the actual network call too, so is there a attribute in adview i can use etc ? Its necessary to do it by xml because im going to incorporate data binding to turn the ad on and off.

j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • [this](http://stackoverflow.com/questions/4549401/correctly-disable-admob-ads) might help – Rain Man Jan 16 '16 at 04:30
  • To disable network call, you may un-use loadAd() in Java file along with making AdView visibility invisible. Also never fully display your adUnitId publicly – VVB Jan 16 '16 at 04:33
  • This could be handled in code by not calling loadAd() as @VVB mentions. That said if the `AdView` is not visible, ie: `android:visibility="gone"` then it will refuse to load an ad. – Cory Charlton Jan 16 '16 at 04:34
  • thanks visiblity is what i was looking for, i'll set a data binding flag in there to control the visiblity then. thanks .. you can post an official answer if you see fit and i'll consider it highly. – j2emanue Jan 16 '16 at 04:36
  • Use this attribute in xml ads:loadAdOnCreate="False" – VVB Jan 16 '16 at 04:38

1 Answers1

2

How can i disable this ?

As long as you don't call the method to load ad it is similar to disabled. Will not display any ad.

one way is to wrap it around a linearlayout and then hide that layout but i want to disable the actual network call too, so is there a attribute in adview i can use etc ?

It is just a view. Common attributes like visibility, width, height, gravity etc are applicable to this as well.

Its necessary to do it by xml because im going to incorporate data binding to turn the ad on and off.

No you can do it without XML. Just create the adview in your Java code and attach it to your layout. Similarly you can also detach it.

Viral Patel
  • 32,418
  • 18
  • 82
  • 110