Search code examples
androidadmobadview

google Adview in Android - how to set disabled in xml


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.


Solution

  • 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.